Connecting to Oracle


 @oci_connect() 


Two PHP extensions are available for Oracle, but only one is actively maintained and also works with more recent versions of the RDBMS. To install it, configure PHP with the switch with-oci8. The environment variable ORACLE_HOME must be set so that PHP can find the client libraries. Windows users need the php.ini directive extension=php_oci8.dll. In addition, PHP requires read access to the client libraries. Then, oci_connect() tries to establish a connection to the server. The order of the parameters is a bit strange: first username and password, then the name of the service (that has been configured using the configuration assistant or is part of the tnsnames.ora file). The return value is a handle to the connection and is required by further operations in the database.

Connecting to Oracle (oci_connect.php)
 <?php   if ($db = @oci_connect('scott', 'tiger', 'orcl'))     {     echo 'Connected to the database.';     oci_close($db);   } else {     echo 'Connection failed.';   } ?> 

WARNING

In PHP 4, oci_connect() did not exist yet, so for this version, ocilogon() has to be used. However, this is considered deprecated in PHP 5. Therefore, all Oracle phrases in this chapter use the PHP 5 syntax; however, files with the extension .php4 are included in the download repository that work on older PHP versions.





PHP Phrasebook
PHP Phrasebook
ISBN: 0672328178
EAN: 2147483647
Year: 2005
Pages: 193

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net