1

I'm trying to run a very simple Oracle procedure from PHP, using the following statement:

$sql = 'exec procedureName(param1, param2)';
$sql = oci_parse($connection, $sql); oci_execute($sql);

Running this in Oracle SQL developer returns a successful 'anonymous block completed' message, but running this via PHP returns an 'ORA-00900: invalid SQL statement' error.

Is there anyway to run this procedure from PHP? Many thanks

2
  • 2
    Try getting rid of "exec " in $sql. Commented Apr 18, 2012 at 15:35
  • Many thanks, good suggestion but I'm getting the same error Commented Apr 18, 2012 at 15:41

2 Answers 2

6

Looking a little deeper, I think you'll need to put your procedure call inside a PL/SQL BEGIN-END pair, as in:

$sql = 'BEGIN procedureName(:param1, :param2); END;';
$stmt_id = oci_parse($connection, $sql);
oci_bind_by_name($stmt_id, ':param1', $value1);
oci_bind_by_name($stmt_id, ':param2', $value2);
oci_execute($stmt_id);

You'll need to edit the above to use whatever variable names are appropriate in the calls to oci_bind_by_name.

Also note that the presence of semi-colons in the SQL string is important.

Share and enjoy.

Sign up to request clarification or add additional context in comments.

Comments

0
$sql = 'BEGIN procedureName(:param1, :param2); END;';
$stmt_id = oci_parse($connection, $sql);
oci_execute($stmt_id);

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.