Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP ORA-01745: invalid host/bind variable name Warning

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!

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
like image 682
vector Avatar asked Feb 11 '15 21:02

vector


1 Answers

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.

Try changing it to ":finish" or similar and it should work.

like image 52
macl Avatar answered Sep 21 '22 23:09

macl