PHP Connect to Oracle using the OCI function
PHP Connection Visit Oracle is using the OCI function, and the following is a sorted document
1. Installing Apache and PHP Packages
Yum install-y httpd php*
2. Download Oracle Components
oracle-instantclient-basic-10.2.0.4-1.i386.rpm
oracle-instantclient-sqlplus-10.2.0.4-1.i386.rpm
oracle-instantclient-devel-10.2.0.4-1.i386.rpm
oracle-instantclient-odbc-10.2.0.4-1.i386.rpm
#rpm-IVH oracle-instantclient* (four components installed on all)
The/usr/lib/oracle/10.2.0.4/client/lib/directory is generated at this time
3. Modify the/etc/ld.so.conf file
#vim/etc/ld.so.conf
Append the following content
/usr/lib/oracle/10.2.0.4/client/lib/
#ldconfig (Execute command)
4. Download the OCI8 component
Http://pecl.php.net/get/oci8-1.4.1.tgz
#tar ZXVF oci8-1.4.1.tgz
5. Editing the OCI8 module
#cd oci8-1.4.1
#phpize (Execute command)
#./configure--with-oci8=instantclient,/usr/lib/oracle/10.2.0.4/client/lib/
#make Install
After success the system will prompt you: Oci8.so has been successfully placed in the/usr/lib/php/modules/directory
6. Modify the php.ini file
#vim/etc/php.ini
Append the following content
Extension=oci8.so
7. Restart Apache Service
Service httpd Restart
8. Use the Phpinfo () function to view
Code Connection Test Oracle Database
- PHP
- $ Conn = Oci_connect (' Scott ', ' Oracle ', ' 192.168.12.133/ORCL ');
- if (! $conn) {
- $ e = Oci_error ();
- Print htmlentities ($e [' message ']);
- Exit
- }
- $ Query = ' Select Ename,sal from Scott.emp ' ;
- $ Stid = Oci_parse ($conn, $query);
- if (! $stid) {
- $ e = Oci_error ($conn);
- Print htmlentities ($e [' message ']);
- Exit
- }
- $ R = Oci_execute ($stid, oci_default);
- if (! $r) {
- $ e = Oci_error ($stid);
- Echo htmlentities ($e [' message ']);
- Exit
- }
- print ' < Table Border="1">";
- While ($row = oci_fetch_array($stid, Oci_return_nulls)) {
- print ' < TR > ';
- foreach ($row as $item) {
- print ' < TD > '. ($item? Htmlentities ($item): '). ' td>';
- }
- print ' tr>';
- }
- print ' table>';
- Oci_close ($conn);
- ?>
Finally browse the page through the browser