PHP7 How to configure a remote connection to an Oracle database on Windows

Source: Internet
Author: User

As a result of the project requirements, the need to go to other project team Oracle database to get some data, the local configuration of the connection is the Oracle method, stepping over the configuration of Windows on one after another pit, finally completed the configuration, here to share, hope to help people in need.

1. First verify that the read-only account they are given is successful and requires a local installation of the connection tool (Plsql Developer)

2. Configuring the Plsql Developer connection requires downloading the Oracle Instant Client (instantclient_11_2) tool, creating a Tnsnames.ora file that holds the connection database information, and puts it in the tool's directory.

Oracle's clients are aligned with the Oracle version, asking the DBA, We here are 11.2.0.4.0 version, to the Oracle website to download the corresponding client, because the local phpstudy with PHP are 32-bit version, worry about problems, download and PHP version of the same number of users (computer system is 64, and this relationship is not big).

Unzip the client into a directory, and the new Tnsnames.ora is placed in the subdirectory of the client folder.

Put in the following content

test_db=  == = = =            =1521))    )    = =        dbname)   ))

TEST_DB is its own connection name, IP is replaced by the Ip,service_name database name of the remote Oracle.

Join the client's directory to the path path for easy connection to the Plsql Developer.

Add the system variable Oracle_home and save the client directory.

Add system variable Nls_lang, save as simplified Chinese_china. ZHS16GBK to solve the read encoding problem.

After installing Plsql developer, connect to see if you can connect.

3. Open the OCI extension or pdo_oci extension of PHP to connect the test.

PHP7 because there is no extension with php_oci_11g, you need to install to download the corresponding version of the DLL file, put in the PHP ext directory, open the extension in php.ini.

Windows missing Oci.dll file may appear after you turn it on.

Copy the Oci.dll file from the client above to the PHP directory.

Start PHP, see phpinfo inside should appear the following extension:

Attempt to connect to database

try{//$conn = new PDO ("Oci:dbname=//ip:1521/dbname", ' username ', ' password ');//PDO mode   $conn = Oci_connect (' Username ', ' password ', "(Description= (address= (PROTOCOL =tcp) (HOST=IP) (PORT = 1521)) (Connect_data = (sid=dbname)))");   Var_dump ($conn);   echo "Connection succeeded";} catch (Pdoexception $e) {   echo ("Error:". $e->getmessage ());}
    • The PDO method throws the following exception (sqlstate[]: pdo_oci_handle_factory: <<Unknown>> (ext\pdo_oci\oci_driver.c:642) 2017-03-08+1)
    • Normal connection will error (Warning:oci_connect (): Ocienvnlscreate () failed. There is something wrong with your system-please check this PATH includes the directory with Oracle Instant Client Libra Ries

Don't panic about these problems on Windows, and now that you've made sure you've installed the extensions, it's definitely not PHP bugs (I see some of them going to PHP for bugs).

Some people say that the DLL files are all copied to system32 or all copied to PHP and so on. First of all, it is not recommended to copy anything to the C-disk directory, the original is a mess, but also because of their own small function to put the file is certainly unreasonable. Just put it where you use it.

Like the missing Oci.dll file above, because PHP is used, so PHP will first in its own directory to search for the file, put in the PHP directory (of course, it may be possible to put under the System32)

Because of the configuration for a long time, a little upset, I simply copied the entire client file into the PHP directory, the test no longer appear above the error, then the proof is because the lack of a file above caused. I am here in the form of a nginx+phpcgi. At this time if the copy to the PHP directory is deleted, some are used to certainly cannot be deleted, after testing, only the following file and just the Oci.dll file cannot be deleted.

This file also has a very big feature, which encapsulates a lot of function extension what.

Now you're done, test the PHP code above:

    • PDO form Print Connection type (

      Object (PDO) #1 (0) {
      }

    • Normal connection return connection type (resource (5) of type (Oci8 connection))

Summarize:

Do not trust those who answer to the System32, all the files where the file, this will lead to the system directory confusion, when they can not find, even if the problem is not clear thinking, may be the solution of their own inexplicable (actually no use)

PHP7 How to configure a remote connection to an Oracle database on Windows

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.