Oracle 10g Instant Client (free download) is a remote Oracle database connection with PHP the easiest way, only need to install three libraries.
PHP access Oracle's current API Instant Client libraries used by the called OCI8. (The C interface, the name was first introduced in Oracle8.) PHP Oracle 8 Functions can call Oracle 8.1.7,9. X or 10.x , or you can for convenience, use the optional abstract class, such as PEAR MDB2 and ADOdb.
Instant Client can also use the older version of PHP "oracle" extension, but it calls do not support the use of the Oracle API. PHP community or Oracle do not recommend using this extension for new development.
Apache will be the Instant Client with PHP 4 or used together, follow these steps. Requires an existing Oracle database; Instant Client does not provide Oracle database. Typically, this database will be located on other computers. If the database is located locally, the Oracle component generally already available, so do not need Instant Client.
Software Requirements: Software Notes
Oracle Instant Client download the "Instant Client Package - Basic". In Linux, also download the "Instant Client Package - SDK".
Apache HTTPD Server PHP community still recommends Apache 1.3
PHP - PHP Hypertext Processor 4.3 or later
In Windows, enable the PHP OCI8 extension
Instant Client binary file is the Windows pre-built PHP binary file to add.
Download PHP binary zip file (not the installer version) and Apache. In accordance with the PHP manual installation on Windows systems to install them. OTN open source development Center contains helpful links to background information, such as "in Windows 2000/XP to install Oracle, PHP and Apache", which describes how to install the tradition of integrity of the Oracle 10g version (Instant Client does not need this version ).
Before proceeding, check PHP is running. Oracle support is not enabled for this phase.
The Instant Client from the OTN download page for Windows, Instant Client Basic package. This compressed file size is about 30MB.
Create a subdirectory (for example, c: instantclient10_1), and then copy the following from the compressed file library:
oraociei10.dll
orannzsbb10.dll
oci.dll
These three documents about the total size of 80MB.
To use the older PHP version of "oracle" extension (in php.ini to use "extension = php_oracle.dll" enabled), then copy ociw32.dll not oci.dll.
Edit this environment, it will c: instantclient10_1 added to the PATH (in the other Oracle directory before).
For example, in Windows 2000, click "Start" -> "Settings" -> "Control Panel" -> "System" -> "Advanced" -> "Environment Variables", edit the system variables list in the PATH.
If you use the tnsnames.ora file defines the Oracle Net service names, will be copied tnsnames.ora to c: instantclient10_1, and the user environment variable TNS_ADMIN is set to c: instantclient10_1. You can also define the user environment variable LOCAL default service name.
Set the necessary Oracle globalization language environment variables such as NLS_LANG. If not set, use the default local environment. For more detailed information, see Oracle PHP global overview of the application.
Oracle do not set unnecessary variables such as ORACLE_HOME and ORACLE_SID.
Editing php.ini, not to OCI8 extension set Notes:
extension = php_oci8.dll
Extension_dir directive will set the full path of PHP extension DLL. In PHP 4 in, DLL in the PHP software "extensions" subdirectory. In PHP 5, which is located in "ext" in.
Restart Apache.
To check whether the configuration of the expansion can be read at the web server where to create a simple PHP script.
Php
phpinfo ();
?>
Use the "http://" URL to load this script in your browser. Browser page should contain a display "OCI8 Support enabled" the "oci8" section.
In Linux, enable PHP OCI8 extension
To add Oracle connectivity on Linux, need to recompile PHP.
Open Source Developer Center contains links to useful background information, such as the Linux install Oracle, PHP and Apache, it describes how to install the traditional, full version of Oracle 10g (Instant Client does not need this version).
Download and install Apache. For example, in your home directory to install it:
cd apache_1.3.31
. / Configure - enable-module = so - prefix = $ HOME / apache - with-port = 8888
make
make install
Edit $ HOME / apache / conf / httpd.conf and add:
AddType application / x-httpd-php. Php
AddType application / x-httpd-php-source. Phps
Download and extract the PHP.
From the OTN Instant Client page on the download Basic and SDK Instant Client package. The total size of the two RPM is about 30MB.
To install as root user RPM.
rpm-Uvh oracle-instantclient-basic-10.1.0.3-1.i386.rpm
rpm-Uvh oracle-instantclient-devel-10.1.0.3-1.i386.rpm
The first RPM will be placed on Oracle database / usr/lib/oracle/10.1.0.3/client/lib, the second RPM in / usr/include/oracle/10.1.0.3/client to create the first (header).
Back up this patch and then apply it to PHP's ext/oci8/config.m4. The line number of the patch is based on PHP 4.3.9 in. If you have fixed PHP error 31084 (most likely PHP 4.3.11 and 5.0.4 have been fixed), then do not need this patch.
If you are using PHP 4.3.9 or 4.3.10, you can save this patch to a file (such as php_oci8ic_buildpatch), and then install it using the following command:
patch-u config.m4 php_oci8ic_buildpatch
This patch creates a new PHP configuration parameter: - with-oci8-instant-client [= DIR]. In Linux, by default, it uses the RPM is installed from the latest version of Instant Client. You can specify the directory where the Oracle database using other versions. In any case, it will automatically use the correct SDK headers.
New parameters and existing - with-oci8 parameter mutually exclusive.
For example: In the non-Linux platforms, the Instant Client package extract to a directory of your choice. - With-oci8-instant-client parameters will need to explicitly specify this directory; for example, - with-oci8-instant-client = / home/instantclient10_1. Instant Client SDK should unzip the package with the basic same directory in order to modify the configuration script after the header file can be found in the subdirectory.
In the top-level PHP directory to rebuild "configure" script.
cd php-4.3.9
rm-rf autom4te.cache config.cache
. / Buildconf - force
Using the new option to run configure. This example uses installed in the home directory of the Apache.
. / Configure - with-oci8-instant-client - prefix = $ HOME / php - with-apxs = $ HOME / apache / bin / apxs - enable-sigchild - with-config-file-path = $ HOME / apache / conf
Reconstruction of PHP.
make
make install
Copy the PHP configuration - with-config-file-path specified location
cp php.ini-recommended $ HOME / apache / conf / php.ini
The LD_LIBRARY_PATH set to / usr/lib/oracle/10.1.0.3/client/lib and restart Apache.
If you use the tnsnames.ora file defines the Oracle Net service name, will TNS_ADMIN set to directory containing this file.
Apache should be set before the start of all Oracle environment variables. The following script can help do this:
#! / Bin / sh
APACHEHOME = / home / apache
LD_LIBRARY_PATH = / usr/lib/oracle/10.1.0.3/client/lib: $ (LD_LIBRARY_PATH)
TNS_ADMIN = / home
export LD_LIBRARY_PATH TNS_ADMIN
echo Starting Apache
$ APACHEHOME / apachectl start
To confirm whether the configuration of the expansion, please read the local web server can create a simple PHP script.
Php
phpinfo ();
?>
Using a similar "http://localhost:8888/
Connect to Oracle
Oracle connection information is passed to the OCILogon () to create a connection. Instant Client and associated tools are often "stay away from" any database server, Oracle Net connection identifier must be the user name and password used together. The Oracle database has been established, connection information may be known. For the new system, this information by the Oracle installer to install the database to provide. This installation procedure should be configured Oracle Net and created a service name.
In the new database, you may need to demo mode (such as the HR user) and provide a password to unlock. Also available via the SQL * Plus in order to SYSTEM user to connect and execute the following statement to do this:
ALTER USER username IDENTIFIED BY new password ACCOUNT UNLOCK;
The connection information is passed to PHP There are many ways. The first example uses Oracle 10g's Easy Connect syntax to connect to the mymachine MYDB database service running in the HR mode. Oracle Network does not require tnsnames.ora or other documents:
$ C = OCILogon (''hr'',''hr_password'',''/ / mymachine.mydomain / MYDB'');
The Easy Connect syntax, see the Oracle Easy Connect naming method to use the document.
Or, if / home / tnsnames.ora contains:
MYDB =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP) (HOST = mymachine.mydomain) (PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = MYDB)
)
)
And TNS_ADMIN environment variable is set to / home (before you start Apache), the connection string can be:
$ C = OCILogon (''hr'',''hr_password'',''MYDB'');
If the environment variable LOCAL (Windows) or TWO_TASK (in Linux) is set to MYDB, you can use the following code generation and MYDB connection:
$ C = OCILogon (''hr'',''hr_password'');
Use Oracle
When the basic connection is available, try running a simple script testoci.php. Depending on your database to modify the connection details and load it in your browser. This example lists all tables owned by the user HR:
Php
$ Conn = OCILogon ("hr", "hr_password",''/ / mymachine.mydomain: port / MYDB);
$ Query =''select table_name from user_tables'';
$ Stid = OCIParse ($ conn, $ query);
OCIExecute ($ stid, OCI_DEFAULT);
while ($ succ = OCIFetchInto ($ stid, $ row)) (
foreach ($ row as $ item) (
echo $ item. "";
)
echo "
n";
)
OCILogoff ($ conn);
?>
Diagnosis
Oracle PHP troubleshooting FAQ contains useful information on connecting Oracle.
Instant Client download page from Oracle's SQL * Plus command-line tools to help solve environmental problems and connection problems. See SQL * Plus Instant Client Release Notes.
Check SQL * Plus using the environment is the environment and the phpinfo.php shows the same.
Windows Help
If the phpinfo.php script does not generate display "OCI8 Support enabled" to "oci8" section, then there is no will confirm in the php.ini "extension = php_oci8.dll" Make notes.
If the PATH is set incorrectly, or can not find the Oracle database, then start Apache will display a warning: "can not find the path specified dynamic link library OCI.dll." Phpinfo () page of the Environment section will show the value of PATH, and PHP actual use of the Oracle variables.
If the php.ini the extension_dir directive is incorrect, then start Apache will display a warning: "PHP Startup: Unable to load dynamic library php_oci8.dll."
Linux Help
Carefully check if the correct fixed config.m4. If the "configure" fails, check the config.log file. Restore config.m4, delete cache files, run. / Buildconf - force and configure, verify whether the problem is related with the changes.
Ensure that the "configure" on the stamp is present. Delete all cache files, and rebuild it if necessary.
Start Apache in the shell to set all the necessary Oracle environment variables.