PHP remote connection to Oracle database operation method

Posted on

In this paper, an example is given to illustrate the implementation of PHP remote connection to Oracle database. To share with you for your reference, as follows:

1、 The following are the operation steps of accessing Oracle database based on PHP of wampserver:

1. Step 1: let PHP support OCI

First of all, install the integrated running environment of PHP. There are many integrations on the Internet. What I install is wampserver (for specific installation methods, please refer to another article I wrote earlier). After installation, find the php.ini file from the installation directory. For example, my local path is D: Wamp bin PHP php5.3.3, which uses php_oci8.dll in php.ini; Remove, that is to say, remove the annotation, which is equivalent to using PHP ABCD oci8.

2. Step 2: after wampserver is running, check PHP ﹐ oci8 in PHP > PHP extensions

[other integration environments can also be used, such as phpstudy. We can directly check the PHP extension options for them].

3. Step 3: Oracle database file configuration

For a PC with an Oracle client, you can install the configuration file, tnsnames.ora file, in Oracle. This file path is the path to install oracle. For example, my native is

F: Oracle product 10.2.0 client 1 network admin, the connected database. The configuration details are as follows (if is displayed, the default is local):

   (ADDRESS = (PROTOCOL = TCP)(HOST = = 1521))
   (SERVICE_NAME = orcl)

4. Step 4: check whether oci8 is configured successfully

① In general, opening localhost will display the phpinfo.php interface, which is the PHP information. You can use “Ctrl + F” to search “OCI” to see if there is a corresponding OCI module. Of course, there is a little PHP based file that you can access directly. Remember to add“echo phpinfo();“Yes.

② . don’t be too happy. Go to this step. At least I can’t find the corresponding information. At this time, you can follow some suggestions on the Internet and put thephp_oci8.dllCopy to system32 directory

③ . finally, it is recommended to restart the service, preferably the computer (I found that restarting the service was useless during the test. Once, the OCI extension was accidentally refreshed, so if the operation method is correct, I suggest to restart.)

2、 Code test remote connection to orcal database (it is recommended to use your own Oracle client to try to connect to the other server to ensure the success rate of the operation)

* Created by PhpStorm.
* User: Administrator
* Date: 2015/12/7
* Time: 16:25

//Configure parameters for connecting database
(INSTANCE_NAME = orcl)))"
= oci_connect ('scott ',' Tiger ', $dbstr); // if the last parameter is removed or is'', the default connection is local
= oci_parse($conn, "select * from mono");
= oci_fetch_all($stmt, $results);
if ($nrows > 0) {
"<table border="1"">

Leave a Reply

Your email address will not be published.