PHP connection to access Oracle uses the oci function. The following is a compiled document
1. Install 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* (all four components installed)
At this time, the /usr/lib/oracle/10.2.0.4/client/lib/ directory will be generated
3. Modify the /etc/ld.so.conf file
#vim /etc/ld.so.conf
Add the following content
/usr/lib/oracle/10.2.0.4/client/lib/
#ldconfig (execution command)
4. Download OCI8 component
#tar zxvf oci8-1.4.1.tgz
5. Edit 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
Add the following content
extension=oci8.so
7. Restart the Apache service
service httpd restart
8. Use the phpinfo() function to view
9. Edit the php code to connect and test the oracle database
$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 '
'.($item?htmlentities($item):' ').' | ';
This article comes from the blog "You can't reach a thousand miles without taking small steps". Reprinting is strictly prohibited!