0

I have got this mysql query:

$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);

i would like to know how i can convert it to a Oracle Database query.

I found this code but it does not work:

    $stid = oci_parse($dbconn, 'INSERT INTO  evento (ideventoPrecedente, data, orario, creatoreEvento, paziente, bisogno) values 
    ($ideventoPrecedente, $data, $orario, $creator, $patient, $bisogno)' );

    oci_execute($stid);

Error:

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 
4
  • You'll need to open a connection with oci_connect(). Use oci_bind_by_name() to bind your parameters. oci_parse() to parse your statement. Lately, oci_execute() to execute the statement handle. Commented Oct 14, 2014 at 18:08
  • 1
    possible duplicate of Inserting data in oracle database using php Commented Oct 14, 2014 at 18:08
  • this the code? OCIBindByName($stid, ":bind1", $crea); OCIBindByName($stid, ":bind2", $idricovero); it is possible get the same code in a unique line? Commented Oct 14, 2014 at 18:23
  • So if i have got 20 variables i have to write 20 times oci_bind_by_name() ? Commented Oct 15, 2014 at 8:09

1 Answer 1

1

In your post, I think your attempt likely didn't work because you have variables in your SQL statement wrapped in single quotes, so the interpreter isn't resolving them to their actual values. You may try fixing that and re-attempting.

Your mileage may vary, but this is the (untested) gist of how to do what you want to do.

// 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);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.