PHP joins Oracle using the OCI function

Source: Internet
Author: User
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


  1. PHP
  2. $ Conn = Oci_connect (' Scott ', ' Oracle ', ' 192.168.12.133/ORCL ');
  3. if (! $conn) {
  4. $ e = Oci_error ();
  5. Print htmlentities ($e [' message ']);
  6. Exit
  7. }
  8. $ Query = ' Select Ename,sal from Scott.emp ' ;
  9. $ Stid = Oci_parse ($conn, $query);
  10. if (! $stid) {
  11. $ e = Oci_error ($conn);
  12. Print htmlentities ($e [' message ']);
  13. Exit
  14. }
  15. $ R = Oci_execute ($stid, oci_default);
  16. if (! $r) {
  17. $ e = Oci_error ($stid);
  18. Echo htmlentities ($e [' message ']);
  19. Exit
  20. }
  21. print ' < Table Border="1">";
  22. While ($row = oci_fetch_array($stid, Oci_return_nulls)) {
  23. print ' < TR > ';
  24. foreach ($row as $item) {
  25. print ' < TD > '. ($item? Htmlentities ($item): '). ' td>';
  26. }
  27. print ' tr>';
  28. }
  29. print ' table>';
  30. Oci_close ($conn);
  31. ?>

Finally browse the page through the browser




  • 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.