Install PHP and Oracle 10g real-time client

Source: Internet
Author: User
Tags php error php software

To confirm whether the extension is configured, create a simple PHP script where the Web server can read it.

<?php 
phpinfo();
?>

Load the script to the browser using a URL similar to "http: // localhost: 8888/<path>/phpinfo. php. The browser page should contain an "oci8" section showing "oci8 support enabled.

Connect to Oracle

The Oracle connection information is passed to ocilogon () to create a connection. And Instant Client
Associated tools are usually "Far Away" from any database server, so the Oracle Net connection identifier must be used with the user name and password. For the created Oracle
The database and connection information may be well known. For new systems, this information is provided by the Oracle installer when installing the database. This installer should be configured with Oracle Net
And creates a service name.

In the new database, you may need to unlock the demo mode (such as the HR user) and provide it with a password. You can also connect to SQL * Plus as a system user and execute the following statements to complete this operation:

Alter User Username identified by new password account unlock;

There are multiple ways to pass connection information to PhP. In the first example, connect to
HR mode in mydb Database Service Running on mymachine. Tnsnames. ora or other Oracle network is not required
File:

$c = OCILogon('hr', 'hr_password', '//mymachine.mydomain/MYDB');

For more information about the easy connect syntax, see the documentation on using the easy connect naming method in Oracle.

Or, if/home/tnsnames. ora contains:

MYDB =
(DESCRIPTION=
(ADDRESS = (PROTOCOL = TCP)(HOST = mymachine.mydomain)(PORT = 1521))
(CONNECT_DATA=
(SERVER = DEDICATED)
(SERVICE_NAME = MYDB)
)
)

If the tns_admin environment variable is set to/Home (before Apache is started), the connection string can be:

$c = OCILogon('hr', 'hr_password', 'MYDB');

If the environment variable local (on Windows) or two_task (on Linux) is set to mydb, you can use the following code to generate a connection to mydb:

$c = OCILogon('hr', 'hr_password');

Use Oracle

When the basic connection is available, try to run a simple script testoci. php. Modify the connection details based on your database and load it in your browser. This example lists all tables owned by the user HR:

<?php 
$conn = OCILogon("hr", "hr_password", '//mymachine.mydomain:port/MYDB);
$query = 'select table_name from user_tables';
$stid = OCIParse($conn, $query);
OCIExecute($stid, OCI_DEFAULT);
while ($succ = OCIFetchInto($stid, $row)) {
foreach ($row as $item) {
echo $item." ";
}
echo "<br>/n";
}
OCILogoff($conn);
?>

Fault Diagnosis

Oracle PHP troubleshooting FAQs include useful information about connecting to Oracle.

You can download the Oracle SQL * Plus command line tool from the Instant Client page to solve environment and connection problems. For more information, see SQL * Plus Instant Client.

Check whether the environment used by SQL * Plus is the same as that displayed by phpinfo. php.

Windows Help

If the phpinfo. php script does not generate the "oci8" section showing "oci8 support enabled", make sure that "extension = php_oci8.dll" is not set as a comment in PHP. ini.

If the path is set incorrectly or the Oracle database cannot be found, start Apache with a warning: "Dynamic Link Library cannot be found in the specified path.
OCI. dll ." The Environment Section on the phpinfo () page displays the PATH value and the Oracle variables actually used by PHP.

If the extension_dir command of PHP. INI is incorrect, the following warning is displayed when Apache is started: "php startup: cannot load dynamic library php_oci8.dll ."

Linux help

Check whether config. M4 is fixed correctly. If "Configure" fails, check the config. log file. Restore config. M4, delete the cache file, run./buildconf -- force and configure, and verify whether the problem is related to the change.

Make sure that the timestamp on "Configure" is current. Delete All cached files and recreate them if necessary.

Set all necessary Oracle environment variables in the Apache shell.

Conclusion

I hope this article will help you. You can post questions and suggestions on the OTN Instant Client or PHP forum.

 

Oracle 10g Instant Client is the easiest way to connect PHP to a remote ORACLE database. It only needs to install three databases.

The instant client library used by PHP to access Oracle's current API is called oci8.
Introduced in oracle8 .) PHP Oracle 8 functions can directly call Oracle 8.1.7, 9.x, or
10. X, or you can use optional abstract classes such as pear mdb2 and ADODB for convenience.

The instant client can also use an earlier version of PHP "oracle" extension, but it calls an unsupported Oracle API. We recommend that you do not use this extension for new development in PHP or Oracle.

To use the Instant Client with PHP 4 in Apache, follow these steps. An existing Oracle
Databases; instant client does not provide Oracle databases. Generally, this database is located on another computer. If the database is located locally
Oracle components are generally available, so you do not need Instant Client.

Software requirements:

Software Notes
Oracle Instant Client Download "Instant Client package-basic ".
In Linux, you should also download "Instant Client package-SDK ".
Apache httpd server Apache 1.3 is still recommended in the PHP Field
Php-PHP hypertext Processor Version 4.3 or later


Enable PHP oci8 extension on Windows

The instant client binary file is a supplement to PhP's windows pre-built binary file.

  1. Download PHP binary compressed files (not the installer version) and Apache. Follow the instructions in the PHP Manual
    Install them on Windows. OTN's Open-Source Developer Center contains links to useful background information, such as "install on Windows 2000/XP
    Oracle, PHP, and Apache ", which describes how to install the traditional and Complete Oracle 10g version (Instant Client
    This version is not required ).

    Check whether PHP is running normally before continuing the operation. Oracle Support is not enabled at this stage.

  2. Download the Instant Client Basic Package for Windows from the Instant Client page of OTN. The size of the compressed file is about 30 mb.

  3. Create a sub-directory (for example, C:/instantclient10_1) and copy the following library from the compressed file:

    • Oraociei10.dll
    • Orannzsbb10.dll
    • OCI. dll

    The total size of these three files is about 80 Mb.

    To use an earlier version of the "oracle" extension of PHP (Enabled with "extension = php_oracle.dll" in PHP. INI), copy ociw32.dll instead of OCI. dll.

  4. Edit this environment and add C:/instantclient10_1 to path (before other Oracle Directories ).

    For example, on Windows 2000, choose Start> Settings> Control Panel> system> advanced> environment variables ", edit the path in the system Variable list.

    For example
    If you use the tnsnames. ora file to define the Oracle Net service name, copy tnsnames. ora
    C:/instantclient10_1 and set the user environment variable tns_admin
    C:/instantclient10_1. You can also define the default service name in the local environment variable.

    Set the required Oracle global language environment variables, such as nls_lang. If this parameter is not set, the default local environment is used. For more details, see the overview of Oracle PHP application globalization.

    You do not need to set unnecessary Oracle variables, such as ORACLE_HOME and oracle_sid.

  5. Edit PHP. ini and do not set the oci8 extension as a comment:

    extension=php_oci8.dll

    Set the extension_dir command to the complete PHP extension DLL path. In PHP 4, the DLL is located in the "extensions" subdirectory of the PHP software. In PHP 5, they are located in "Ext.

  6. Restart Apache.

  7. To check whether extensions are configured, create a simple PHP script where the Web server can read.

    <?php 
    phpinfo();
    ?>

    Use the "http: //" URL to load the script to the browser. The browser page should contain an "oci8" section showing "oci8 support enabled.

    Enable PHP oci8 extension on Linux

    To add an oracle connection to Linux, You need to recompile PHP.

    The open source code Developer Center contains links to useful background information, such as installing Oracle, PHP, and Apache on Linux, it introduces how to install the traditional and Complete Oracle 10g version (this version is not required for Instant Client ).

  8. Download and install Apache. For example, install it in your home directory:
    cd apache_1.3.31
    ./configure --enable-module=so --prefix=$HOME/apache --with-port=8888
    make
    make install

    Edit $ home/Apache/CONF/httpd. conf and add:

    AddType application/x-httpd-php .php
    AddType application/x-httpd-php-source .phps
  9. Download and decompress PHP.

  10. Download the basic and SDK Instant Client packages from the Instant Client page on OTN. The total size of the two RPMs is about 30 mb.

  11. Install RPM as the root user.

    rpm -Uvh oracle-instantclient-basic-10.1.0.3-1.i386.rpm
    rpm -Uvh oracle-instantclient-devel-10.1.0.3-1.i386.rpm

    The first RPM places the Oracle database in/usr/lib/Oracle/10.1.0.3/client/lib, the second RPM creates a header in/usr/include/Oracle/10.1.0.3/client ).

  12. Back up the patch and apply it to ext/oci8/config. M4 of PHP. The patch line number is based on PHP 4.3.9. If php error 31084 has been fixed (probably fixed in PHP 4.3.11 and 5.0.4), this patch is not required.

    If PHP 4.3.9 or 4.3.10 is used, you can save the patch to a file (for example, php_oci8ic_buildpatch) and run the following command to install it:

    patch -u config.m4 php_oci8ic_buildpatch

    This
    Patch creates a new PHP configuration parameter: -- with-oci8-instant-client [= dir]. on Linux, by default, it uses
    The latest version of Instant Client installed in RPM. You can specify Oracle
    To use other versions. In either case, the correct SDK header is automatically used.

    The new parameters are mutually exclusive with the existing -- with-oci8 parameters.

    Example
    For example, on a non-Linux platform
    Decompress the package to the selected directory. With-oci8-instant-client
    The parameter will need to specify this directory explicitly; for example, -- with-oci8-instant-client =/home/instantclient10_1. Should
    The instant client SDK is decompressed to the same directory as the basic package, so that the modified configuration script can find the subdirectory of the header file.

  13. Re-build the "Configure" script in the top-level PHP Directory.
    cd php-4.3.9
    rm -rf autom4te.cache config.cache
    ./buildconf --force
  14. Run configure with the new option. This example uses Apache installed in the main directory.

    ./configure /
    --with-oci8-instant-client /
    --prefix=$HOME/php --with-apxs=$HOME/apache/bin/apxs /
    --enable-sigchild --with-config-file-path=$HOME/apache/conf
  15. Re-build PHP.

    make
    make install
  16. Copy the PHP configuration to the location specified by -- With-config-file-path.

    cp php.ini-recommended $HOME/apache/conf/php.ini
  17. Set LD_LIBRARY_PATH to/usr/lib/Oracle/10.1.0.3/client/lib and restart Apache.

    If the tnsnames. ora file is used to define the Oracle Net service name, set tns_admin to the directory containing the file.

    Set all Oracle environment variables before starting Apache. The following script can help with this operation:

    #!/bin/sh
    APACHEHOME=/home/apache
    LD_LIBRARY_PATH=/usr/lib/oracle/10.1.0.3/client/lib:${LD_LIBRARY_PATH}
    TNS_ADMIN=/home
    export LD_LIBRARY_PATH TNS_ADMIN
    echo Starting Apache

  18. $APACHEHOME/apachectl start
Related Article

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.