Home  >  Article  >  Backend Development  >  PHP connection oracle database_PHP tutorial

PHP connection oracle database_PHP tutorial

WBOY
WBOYOriginal
2016-07-14 10:06:441037browse

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
PHP connection oracle database_PHP tutorial

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 '

';

while($row = oci_fetch_array($stid, OCI_RETURN_NULLS)) {

print '';

foreach($row as $item) {

print '';

}

print '';

}

print '
'.($item?htmlentities($item):' ').'
';

oci_close($conn);

?>
Finally browse the page through the browser
PHP connection oracle database_PHP tutorial

This article comes from the blog "You can't reach a thousand miles without taking small steps". Reprinting is strictly prohibited!

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/477919.htmlTechArticlePHP connection to access Oracle uses the oci function. The following is the compiled document 1. Install Apache and php package yum install -y httpd php* 2. Download the Oracle component oracle-instantclient-basic-10.2.0.4-1.i386...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn