我有几个 php 变量想插入到 oracle 表中,但我很难使用转义引号。
这是我到目前为止所拥有的:
<?php
......
$number_passed=20;//this is calculated earlier in the code
$number_total=100;//also calculated earlier in the code
$date=date('m/d/y');
$username=//username here
$password=//password here
$database=//database connection string here
$connection=oci_connect($username,$password,$database);
$sql="INSERT INTO TEST_TABLE (Date_Col,num_pass,num_total)
VALUES ('"$date"','"$number_passed"','"$number_total"')";
$st= oci_parse($$connection, $sql);
oci_execute($st);
?>
当我这样做时,我收到以下错误:P arse错误:语法错误,意外T_VARIABLE在我声明 sql 语句的行上。如何将 php 变量正确插入数据库表?
另外,我知道我应该在将 php 变量插入数据库之前对其进行清理。有没有为我做这件事的功能?
谢谢!
简单的字符串连接问题。
VALUES ('${date}','${number_passed}','${number_total}')";
甚至不需要逃避口译员。