我有一个PHP数据库应用程序,尝试使用OCI函数绑定和绑定字符串变量时遇到错误。如果绑定大小太大,则这些值将绑定到错误的数据库字段中(没有Oracle,PHP或OCI错误;数据仅以错误的列结尾)。我已经编写了以下代码,这些代码确定了我可以在使用的每台服务器上使用的最大绑定大小值。它有效,但是我不明白为什么会有这样的限制。它与PHP .INI参数有关吗?在运行相同PHP和Oracle版本的不同服务器(范围从1333到4000)上,该限制是不同的。我已经检查了所有我能想到的地方,但无法给出答案。我正在运行Zend Studio 7.2.1和Oracle 11 / g。任何帮助将不胜感激。
// Determine value of MAXBINDSIZE. Note a database connection has already been established in "$conn".
$backupBy = "CAC";
$backupStatus = "Success";
$mx = 8000;//largest reasonable value (for me).
$my = $mx / 2;
$maxBindSize = 1000;//smallest reasonable value (for me).
$i = 0;
while ($my > 1)
{
$name = "TEST-" . $mx;
$query = "INSERT INTO DB_INFO (NAME, BACKUP_BY, BACKUP_STATUS)
VALUES ('{$name}', :BACKUPBY, :BACKUPSTATUS) RETURNING NAME INTO :NAME";
if ($q = oci_parse($conn, $query))
if (oci_bind_by_name($q, ":BACKUPBY", $backupBy, $mx))
if ( oci_bind_by_name($q, ":BACKUPSTATUS", $backupStatus, $mx))
if ( oci_bind_by_name($q, ":NAME", $name, $mx))
if (oci_execute($q))
{
$query = "select * from db_info where name='{$name}'";//'read back what we just wrote...
if (($q = oci_parse($conn, $query)) && oci_execute($q)) $row = oci_fetch_array($q);
}
if (!isset($row["BACKUP_BY"]) || ($row["BACKUP_BY"] != "{$backupBy}") || ($row["BACKUP_STATUS"] != "{$backupStatus}"))
$mx = $mx - $my;//no go, reduce max bind size
else
{
$maxBindSize = $mx; //save last successful value.
$mx = $mx + $my;
}
unset($row);
$my = intval($my / 2);
$i++;
if (($mx < 1000) ||($mx > 8000) || ($i > 16)) $my = 0;//paranoia
}
// Cleanup table, delete bogus entries and save largest successful value for next time.
$query = "delete from db_info where substr(name,1,4) = 'TEST'";
if ($q = oci_parse($conn, $query)) oci_execute($q);
$_SESSION["MAXBINDSIZE"] = $maxBindSize;
//