Php connection to oracle Database

Source: Internet
Author: User
Php connection to access Oracle is using the oci function, the following is the finishing documentation 1. install Apache and php package yuminstall-yhttpdphp * 2. download the Oracle component oracle-instantclient-basic-10.2.0.4-1.i386.rpmoracle-instantclient-sqlplus-10.

The oci function is used to connect to Oracle using php. the following documents are provided:
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 are installed)
The/usr/lib/oracle/10.2.0.4/client/lib/directory is generated.
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
# Tar zxvf oci8-1.4.1.tgz
5. edit 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
The system will prompt you that oci8.so has been successfully put into 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 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.20./ 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 a browser

This article is from the blog "no matter how many miles you have done". I am not allowed to repost it!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.