0

Any thoughts on why the query works in SQLDeveloper but in php it doesn't?

$update = " update TABLENAME SET LASTMOD=current_timestamp WHERE TABLE_NAME=$table ";
$stmt = oci_parse($conn, $update);
oci_execute($stmt, OCI_DEFAULT);
oci_free_statement($stmt);
0

2 Answers 2

4

I'm assuming that your variable $table does not include quotes and it must be quoted in the WHERE clause:

$update = " update TABLENAME SET LASTMOD=current_timestamp WHERE TABLE_NAME='$table'";

A call to oci_error() would reveal any syntax errors in your query.

Note also, that according to the documentation, if this is PL/SQL the statement must end in a ; as

$update = " update TABLENAME SET LASTMOD=current_timestamp WHERE TABLE_NAME='$table';";

The statement would be better done as a proper prepared statement though, with bound parameters:

$update = " update TABLENAME SET LASTMOD=current_timestamp WHERE TABLE_NAME=:table;";
$stmt = oci_parse($conn, $update);
oci_bind_by_name($stmt, ':table', $table);
$result = oci_execute($stmt, OCI_DEFAULT);
if (!$result) {
  echo oci_error();   
}
Sign up to request clarification or add additional context in comments.

1 Comment

thanks for properly prepared statement, though that didn't fix the problem. the problem was oci_default not committing.
1

Found the solution. OCI_DEFAULT doesn't commit so I needed to change it to:

oci_execute($stmt, OCI_COMMIT_ON_SUCCESS);

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.