April 20, 2014
Hot Topics:
RSS RSS feed Download our iPhone app

Combining an Oracle Database with PHP to Manage Data, Page 2

  • October 5, 2007
  • By Deepak Vohra
  • Send Email »
  • More Articles »

If any of the configuration directives is modified, restart the Apache2 server. The Oracle OCI8 PHP class library provides various functions to connect to the Oracle database, run SQL statements, and retrieve result sets. Some of the commonly used OCI8 PHP 5 functions are discussed in Table 2. All the OCI8 PHP functions return FALSE on error.

Table 2: OCI8 Extension Functions

Method Description
oci_connect ( string username, string password [, string db [, string charset [, int session_mode]]] ) Connects to the Oracle server. The db parameter specifies the Oracle instance or the name of the entry in the tnsnames.ora. If db is not specified, the ORACLE_SID environment variable value is used. The charset parameter may be specified if the Oracle server version is >9.2. The default value of session_mode is OCI_DEFAULT. For privileged connections using external credentials, specify the session_mode value as OCI_SYSOPER or OCI_SYSDBA. Privileged connections are disabled by default. To enable privileged connections, set PHP configuration directive oci8.privileged_connect to "1".
oci_close ( resource connection ) Closes an Oracle connection.
oci_new_connect ( string username, string password [, string db [, string charset [, int session_mode]]] )

Establishes a new connection to the Oracle database. The oci_connect() method returns the same connection resource if invoked more than once with the same parameters. In contrast, oci_new_connect() method does not cache connections and returns a new connection.

The parameters are the same as the oci_connect() method.

oci_pconnect ( string username, string password [, string db [, string charset [, int session_mode]]] ) Creates a persistent connection with the Oracle database. Persistent connections are cached and reused between connection requests; this results in increased performance because connections are not created and closed frequently. Persistent connections may be tuned with configuration directives oci8.persistent_timeout, oci8.max_persistent, and oci8.ping_interval. The method parameters are the same as for oci_connect() and oci_new_connection().
oci_parse ( resource connection, string query ) Prepares a SQL statement for execution. Returns a statement resource that may be used with oci_bind_by_name function to bind PHP variables to placeholders. A prepared statement is run with the oci_execute () function.
oci_bind_by_name ( resource stmt, string ph_name, mixed &variable [, int maxlength [, int type]] ) Binds a PHP variable to a placeholder in a prepared statement. The maxlength parameter specifies the maximum length of the bind variable. If maxlength is set to -1, the current length of the variable is used to set maxlength. The type parameter is used bind abstract data types such as LOB/ROWID/BFILE.
oci_execute ( resource stmt [, int mode] ) Executes a previously parsed statement. The mode parameter specifies the mode of execution, the default value being OCI_COMMIT_ON_SUCCESS. To not commit statements on completion, set mode to OCI_DEFAULT. The OCI_DEFAULT mode creates transactions that are rolled back when a connection is closed or when a script has run. With the OCI_DEFAULT mode, commit a transaction with oci_commit() or rollback the transaction with oci_rollback(). Returns TRUE if the statement executes without error and FALSE if the statement does not execute.
oci_error ( [resource source] ) Returns the last error found for the specified resource. For a connection resource, the resource parameter should not be specified. Returns FALSE if no error is found. If an error is found, the error is returned as an array consisting of an error code and error message string.
oci_commit ( resource connection ) Commits all outstanding statements for the active transaction for the specified connection resource. Returns TRUE if the statements get committed and FALSE if an error occurs.
oci_rollback ( resource connection ) Rolls back outstanding statements for the active transaction on the specified connection resource. Returns TRUE if the statements get rolled back and FALSE if an error occurs.
oci_statement_type ( resource statement ) Returns the type of a statement, as one of the following values: SELECT, INSERT, UPDATE, CREATE, DELETE, DROP, ALTER, DECLARE, BEGIN, UNKNOWN. The statement parameter is a statement resource returned by oci_parse() method.
oci_set_prefetch ( resource statement [, int rows] ) Sets number of rows to be pre-fetched after successful statement execution. Default value is 1. Returns TRUE on success, and FALSE on error.
oci_fetch_all ( resource statement, array &output [, int skip [, int maxrows [, int flags]]] )

Fetches all the rows in a result data (for a SELECT statement) into an array. Null fields are set to PHP NULL value. Returns the number of rows fetched, or FALSE if an error occurs. The "skip" parameter specifies the initial number of rows to skip in fetching rows from result set; the default is to not skip any rows. The "maxrows" parameter specifies the maximum number of rows to fetch; the default is to fetch all the rows. The "flags" parameter may set to one of the following values:

OCI_FETCHSTATEMENT_BY_ROW,

OCI_FETCHSTATEMENT_BY_COLUMN, (the default)

OCI_NUM,

OCI_ASSOC.

oci_fetch ( resource statement )

Fetches the next row into the result-buffer.

Returns TRUE if the next row gets fetched, or FALSE if no next row or if an error occurs.

oci_fetch_row ( resource statement ) Fetches the next row from a result set into a numeric array (0 based). Returns FALSE if no more rows. Null fields are set to PHP NULL value.
oci_fetch_object ( resource statement ) Returns the next row in a result set as an object. The object attributes correspond to fields in the statement. Oracle returns all field names in upper case; therefore, all attributes in the row object are in uppercase. Returns FALSE if no more rows in the result set.
oci_fetch_array ( resource statement [, int mode] )

Returns the next row from the result set as a numeric array (0 based), an associative array or both. Returns FALSE if an error occurs or no more rows in the result set to fetch. Associative indices in the result array are uppercase. The mode parameter may be set to any combination of the following:

OCI_BOTH: Returns an array with both associative and numeric indices.

OCI_ASSOC: Returns anassociative array.

OCI_NUM: Returns a numberic array.

OCI_RETURN_NULLS: Creates empty elements for Null fields.

OCI_RETURN_LOBS: Returns the value of a LOB of a descriptor.

oci_fetch_assoc ( resource statement ) Returns the next row from the result set as an associative array. Because Oracle returns field names in upper case, associative indices are in upper case also. Returns FALSE if an error occurs or no more rows to fetch.
oci_num_fields ( resource statement ) Returns the number of result fields in the statement (for a SELECT statement). Returns FALSE on error.
oci_num_rows ( resource stmt ) Returns the number of rows affected by statement execution. For a SELECT statement, it returns the number of rows in the result set. Returns FALSE on error.
oci_field_is_null ( resource stmt, mixed field ) Checks whether field is null. The field parameter may be specified as a field index or field name in uppercase. Returns TRUE if field is null.
oci_field_name ( resource statement, int field ) Returns the field name in uppercase for specified field index ( 1 based).
oci_field_precision ( resource statement, int field ) Returns field precision for a specified field index ( 1 based).
oci_field_size ( resource stmt, mixed field ) Returns field size in bytes. The field may be specified as a field index (1 based) or field name (uppercase).
oci_field_type ( resource stmt, int field ) Returns the field type for a field specified as a field index (1 based).
oci_result ( resource statement, mixed field ) Returns data from the specified field in the current row returned by the oci_fetch() function. The field may be specified as a field index ( 1 based) or field name (uppercase). Returns FASLE on error.
oci_cancel ( resource stmt ) Invalidates a cursor freeing up the associated resources.
oci_free_statement ( resource statement ) Frees up statement resources. For a statement obtained with oci_parse().




Page 2 of 5



Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 


Sitemap | Contact Us

Rocket Fuel