【发布时间】:2015-02-16 19:31:58
【问题描述】:
我有一些 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);
?>
当我这样做时,我收到以下错误:解析错误:语法错误,意外的 T_VARIABLE 在我声明我的 sql 语句的那一行。如何将php变量正确插入到数据库表中?
另外,我知道我应该在将我的 php 变量插入数据库之前对其进行清理。有没有一个函数可以为我做到这一点?
谢谢!
【问题讨论】:
-
使用参数化查询而不是串联。
-
$st= oci_parse($$connection, $sql);到 $st= oci_parse($connection, $sql);
-
感谢您发现错误。
标签: php database oracle oracle-call-interface