title: ORA-06502 String Buffer Too Small from PHP OCI call but not SQL Developer
body: <p>I have written a PL/SQL (Ora10gR2) package which contains a stored procedure. The header looks like this:</p>
  
  <pre><code>procedure updateAddress(
    sid       in     varchar2,
    addID     in out number,
    roomNo    in     varchar2,
    poBox     in     varchar2,
    add1      in     varchar2,
    add2      in     varchar2,
    add3      in     varchar2,
    add4      in     varchar2,
    add5      in     varchar2,
    postCode  in     varchar2,
    country   in     varchar2,
    phone1    in     varchar2,
    phone2    in     varchar2,
    success   out    number
  );
  </code></pre>
  
  <p>The purpose of this procedure is to update/append addresses in the database. If <code>addID</code> is null, it inserts and sets <code>addID</code> to the newly inserted address ID; if <code>addID</code> is not null, it just updates (I haven't written this bit, yet)... Anyway, simple enough.</p>
  
  <p>Calling this procedure works absolutely fine from within SQL Developer. For example, the following works perfectly:</p>
  
  <pre><code>set serveroutput on;
  
  declare
    addID number;
    status number;
  begin
    addID := null;
  
    mypackage.updateaddress('XXX11341976', addID, null, null, 'somewhere', 'else', 'NCx 1234', 'UA', null, null, null, null, null, status);
  
    dbms_output.put_line('Status ' || status || ' - New ID ' || addID);
  end;
  /
  </code></pre>
  
  <p>It outputs something like <code>Status 20 - New ID 3</code>, where 20 is my all OK code and if I query the address table, the new address is sitting there as ID 3.</p>
  
  <p>However, when I call this code from a PHP script, which uses OCI8, I get an <code>ORA-06502</code> error:</p>
  
  <pre><code>ORA-06502: PL/SQL: numeric or value error: character string buffer too small
  ORA-06512: at line 1
  </code></pre>
  
  <p>I know this error usually indicates that you're trying to fit too much data into some type; for example, putting <code>999</code> into <code>number(2)</code>, etc. However, this isn't the case with my SP: there are no limits imposed on the types and, like I say, it works fine in SQL Developer. Likewise, I'm not using <code>dbms_output</code> anywhere in the SP.</p>
  
  <p>This also occurs when I hardcode the PHP script to exactly the same parameters as the above PL/SQL block, or even if I completely remove the body of the procedure and replace it with <code>success := 20</code>. The latter leads me to believe that there's some problem with the OCI call through PHP, rather than my PL/SQL package. However, I haven't got a clue what it might be! I'm using this code elsewhere with, admittedly, simpler procedures, and it works fine.</p>
  
  <p>Any ideas what the source might be, or what I can look for? It's driving me slightly mad!</p>