如何将php变量插入oracle表?

时间:2014-12-18 04:41:21

标签: php database oracle oci

我有一些我想要插入到oracle表中的php变量,但是我很难使用转义引号。

这是我到目前为止所拥有的:

   <?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变量插入数据库之前对其进行清理。是否有一个功能可以帮助我?

谢谢!

1 个答案:

答案 0 :(得分:3)

简单的字符串连接问题。

  VALUES ('${date}','${number_passed}','${number_total}')";

甚至无需逃脱翻译。

相关问题