oracle PHP ORA-01745: 无效的主机/绑定变量名警告
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28464732/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
PHP ORA-01745: invalid host/bind variable name Warning
提问by vector
01745: invalid host/bind variable name warning when running the rollowing code. I am not sure why this is happening please help! I feel like it must be something wrong with my binding but I cannot see what is wrong about it. My $Start and $End variables look like DD-MM-YY. I have listed the PHP code below. Thank you!
01745:运行滚动代码时出现无效主机/绑定变量名称警告。我不知道为什么会这样,请帮忙!我觉得我的绑定一定有问题,但我看不出有什么问题。我的 $Start 和 $End 变量看起来像 DD-MM-YY。我在下面列出了 PHP 代码。谢谢!
PHP:
PHP:
<?php
$year_Echo = '2013';
$yearTruncation = substr($year_Echo, 2);
$yearTruncationMinusOne = $yearTruncation-1;
$Start = ('1-OCT-'.$yearTruncationMinusOne);
$End = ('30-SEP-'.$yearTruncation);
echo "Start = ".$Start." End = ".$End." Year Truncation Minus One = ".$yearTruncationMinusOne."<br>";
/*** connect or WFO DB ***/
$db = oci_connect('query','pw','server:1521/view');
if (!$db){
$e = oci_error();
trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);
}
$query = "SELECT * FROM db.cooldb WHERE (STATUS = 'ACTIVE' OR STATUS = 'CLOSED') AND NUMBER <> ' '
AND AMENDMENT_DATE_CREATED
BETWEEN :start AND :end
ORDER BY AMENDMENT_DATE_CREATED DESC";
$runQuery = oci_parse($db, $query);
oci_bind_by_name($runQuery, ":start", $Start);
oci_bind_by_name($runQuery, ":end", $End);
oci_execute($runQuery);
while($row = oci_fetch_array($runQuery, OCI_ASSOC+OCI_RETURN_NULLS))
{
echo $row['AMENDMENT_DATE_CREATED']." ".$row['TITLE']."<br>";
}
?>
Error:
错误:
Warning:
oci_execute() [function.oci-execute]: ORA-01745: invalid host/bind variable name
回答by macl
The problem is you are using reserved oracle words (namely I think ":end" is the culprit) for a binding variable name, which is not allowed.
问题是您正在使用保留的 oracle 词(即我认为“:end”是罪魁祸首)作为绑定变量名称,这是不允许的。
Try changing it to ":finish" or similar and it should work.
尝试将其更改为 ":finish" 或类似的,它应该可以工作。