我有这个mysql查询:
$ideventoPrecedente = 1;
$data = date ("Y/m/d");
4orario = date ("Y/m/d H:m");
$creator = 3;
$patient = 3;
$bisogno = "i need something";
$qevento= $db->prepare(INSERT INTO event(ideventoPrecedente, data, orario, creatoreEvento, paziente, bisogno ) VALUES(:ideventoPrecedente, :data, :orario, :creator, :patient, :bisogno) );
$qevento->execute($ideventoPrecedente, $data, $orario, $creator, $patient, $bisogno);
我想知道如何将其转换为Oracle数据库查询。
我找到了这段代码,但它不起作用:
$stid = oci_parse($dbconn, 'INSERT INTO evento (ideventoPrecedente, data, orario, creatoreEvento, paziente, bisogno) values
($ideventoPrecedente, $data, $orario, $creator, $patient, $bisogno)' );
oci_execute($stid);
错误:
Warning: oci_execute(): ORA-00911: invalid character in F:\wamp\www\ginevracrm\index.php on line
Warning: oci_fetch_array(): ORA-24374: define not done before fetch or execute and fetch
答案 0 :(得分:1)
在你的帖子中,我认为你的尝试可能不起作用,因为你的SQL语句中的变量用单引号括起来,所以解释器不会将它们解析为它们的实际值。您可以尝试修复并重新尝试。
您的里程可能会有所不同,但这是(未经测试的)如何做您想做的事情。
// Open your database connection
$connection = oci_connect($username, $password, $database);
// Parse your SQL statement
$stmt = oci_parse($connection, "INSERT INTO evento (ideventoPrecedente, data, orario, creatoreEvento, paziente, bisogno) VALUES
(:ideventoPrecedente, TO_DATE(:data, 'YYYY/MM/DD'), TO_DATE(:orario, 'YYYY/MM/DD HH:MI'), :creator, :patient, :bisogno)";
// Define your variables needed for your parsed SQL statement
$ideventoPrecedente = 1;
$data = date ("Y/m/d");
$orario = date ("Y/m/d H:m");
$creator = 3;
$patient = 3;
$bisogno = "i need something";
// Bind the variables to the parsed statement
oci_bind_by_name($stmt, ':ideventoPrecedente', $ideventoPrecedente, -1, SQLT_INT);
oci_bind_by_name($stmt, ':data', $data, -1, SQLT_CHR);
oci_bind_by_name($stmt, ':orario', $orario, -1, SQLT_CHR);
oci_bind_by_name($stmt, ':creator', $creator, -1, SQLT_INT);
oci_bind_by_name($stmt, ':patient', $patient, -1, SQLT_INT);
oci_bind_by_name($stmt, ':bisogno', $bisogno, -1, SQLT_CHR);
// Execute the statement
oci_execute($stmt);