note 1363 modified in function.oci-execute by sixd

From: Date: Wed, 11 Nov 2009 00:23:33 +0000
Subject: note 1363 modified in function.oci-execute by sixd
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-162731@lists.php.net to get a copy of this message
[Editor's note: using '&' with oci_bind_by_name/OCIBindByName parameters is obsolete and can cause errors in any modern PHP] To catch what an error was about, I use a piece of PL/SQl instead of just a SELECT. For instance: <?php $query="BEGIN SELECT user_id INTO :v_user_id FROM rw_users WHERE gebruikersnaam = LOWER(:p_alias); :ERROR := 0; EXCEPTION when others then :ERROR := 1; :SQLCODE := SQLCODE; :SQLERRM := SUBSTR(SQLERRM,0,300); END; "; $stmt = OCIParse($conn, $query); /* Output parameters */ OCIBindByName($stmt,":ERROR",&$insert_error,32); OCIBindByName($stmt,":SQLCODE",&$SQLCODE,32); OCIBindByName($stmt,":SQLERRM",&$SQLERRM,300); OCIBindByName($stmt,":v_user_id",&$v_user_id,32); /* Input parameters */ OCIBindByName($stmt,":p_alias", &$p_alias, strlen($p_alias)+2); $exec_result = OCIExecute($stmt,OCI_DEFAULT); ?> Now if the select causes an exception, it is caught and the error message is stored. --was-- To catch what an error was about, I use a piece of PL/SQl instead of just a SELECT. For instance: <?php $query="BEGIN SELECT user_id INTO :v_user_id FROM rw_users WHERE gebruikersnaam = LOWER(:p_alias); :ERROR := 0; EXCEPTION when others then :ERROR := 1; :SQLCODE := SQLCODE; :SQLERRM := SUBSTR(SQLERRM,0,300); END; "; $stmt = OCIParse($conn, $query); /* Output parameters */ OCIBindByName($stmt,":ERROR",&$insert_error,32); OCIBindByName($stmt,":SQLCODE",&$SQLCODE,32); OCIBindByName($stmt,":SQLERRM",&$SQLERRM,300); OCIBindByName($stmt,":v_user_id",&$v_user_id,32); /* Input parameters */ OCIBindByName($stmt,":p_alias", &$p_alias, strlen($p_alias)+2); $exec_result = OCIExecute($stmt,OCI_DEFAULT); ?> Now if the select causes an exception, it is caught and the error message is stored. http://php.net/manual/en/function.oci-execute.php

« previous php.notes (#162731) next »