作者热门文章
- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我有一些 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 变量插入数据库之前清理它们。有没有适合我的功能?
谢谢!
最佳答案
简单的字符串连接问题。
VALUES ('${date}','${number_passed}','${number_total}')";
甚至不需要逃避解释器。
关于php - 如何将php变量插入到oracle表中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27539355/
我是一名优秀的程序员,十分优秀!