Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

oci_bind_by_name RETURNING INTO truncates value

When I insert a row into a table with 1000+ entries, and attempt to return the row ID (be it from an autoincrement trigger/seq, or from setting the value manually in the insert statement), I get a truncated value:

$db = OCILogon(DATABASE_LOGIN, DATABASE_PASSWORD, DATABASE_NAME);

$mysqldate = date('Y/m/d G:i:s');
$db_vid_id = 748;
$authorID = 310;
$typeID = 2;
$timecode = 47;
$shortDescrip = "hello world";


$query = "INSERT INTO TESTTHOUSAND (ID, VIDEO_ID, AUTHOR_ID, TYPE_ID,
          DATE_CREATED, TIMECODE, SHORT_DESCRIPTION, APPROVED, IS_PUBLIC) 
          VALUES(4067, :videoID, :authorID, :typeID, TO_DATE('$mysqldate','yyyy/mm/dd HH24:MI:SS'),
          :timecode, :shortDescrip, 0, 0) 
          RETURNING ID INTO :id";
$stmt = oci_parse($db, $query);
oci_bind_by_name($stmt, ':videoID', $db_vid_id);
oci_bind_by_name($stmt, ':authorID', $authorID);
oci_bind_by_name($stmt, ':typeID', $typeID);
oci_bind_by_name($stmt, ':timecode', $timecode);
oci_bind_by_name($stmt, ':shortDescrip', $shortDescrip);
oci_bind_by_name($stmt, ':id', $theID);
oci_execute($stmt);
oci_free_statement($stmt);
oci_commit($db);
oci_close($db);

echo $theID;

This code executes properly, and the values are correctly stored in the database. However, the value of $theID is 406, not 4067.

I am running PHP 5.2.6 and Oracle 10.1

Has anyone encountered this before?

like image 762
Jeff Winkworth Avatar asked Nov 10 '09 19:11

Jeff Winkworth


1 Answers

I have done some more digging around and it appears that I need to specify that this is a SQLT_INT:

oci_bind_by_name($stmt, ':id', $annotationID, -1, SQLT_INT);

From http://www.php.net/manual/en/function.oci-bind-by-name.php#92334

for numerics use the default length (-1) but tell oracle its an integer

like image 148
Jeff Winkworth Avatar answered Nov 06 '22 23:11

Jeff Winkworth