oci_bind_by_name RETURNING INTO截断值

时间:2009-11-10 19:38:15

标签: php sql database oracle

当我在一个包含1000多个条目的表中插入一行,并尝试返回行ID(来自自动增量触发器/ seq,或者从insert语句中手动设置值)时,我得到一个截断值:

$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;

此代码正确执行,并且值正确存储在数据库中。但是,$theID的值为406,而不是4067。

我正在运行PHP 5.2.6和Oracle 10.1

有没有人遇到过这个?

1 个答案:

答案 0 :(得分:10)

我已经做了一些挖掘,似乎我需要指定这是一个SQLT_INT:

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

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

  

对于数字使用默认长度(-1)但告诉oracle它是一个整数