The PHP Function OCI_Error
The php function oci_error is used to check for errors in your database calls. Errors are thrown when the database connection fails.
When an error is thrown you get a list of errors including the code and message. The message is usually a long string that describes the problem.
oci_error() can also be called with an argument to set an error handler. Then, every time an error occurs, the error handler will be triggered. This is useful for logging and tracking errors in your application.
There are two methods for connecting to an Oracle database from PHP – the Local Naming and the Easy Connect Naming. Using either method, your web applications can use the Oracle oci_connect function to establish connections.
After a successful connection, you can execute SQL or PL/SQL statements using the oci_execute() function. This includes SELECT, INSERT, UPDATE and DELETE statements.
If a query has an error, oci_error() will return an array of error information. The key to the array is the resource statement and the value is an error message. The error message will be something like
If you want to use oci_error() with a class, you must ensure that the private constructor is not called. Otherwise, an exception will be thrown and the set_error_handler() function will be invoked. Then, the error messages will be logged to the system log file. This is not ideal, because the error handler might not be able to cope with the type of error that is thrown.