How to connect to an Oracle database?

How do you connect to Oracle using PHP on MAC OS X?

+4
source share
5 answers

I would think that OCI is the way to go. PHP has a module for this.

+2
source

The PDO abstraction layer can be used to connect to Oracle DB and perform actions. Here's an article on how to use PDO with Oracle from the Oracle website.

You can also use OCI .

The Oracle PHP Development Center will have a lot of useful information about using Oracle and PHP together.

+2
source

For instantclient on osx 10.6 64bit follow these steps:

download instant client libraries and sdk, write all this in a folder. Make sure you get a 64-bit library, if you are on a 64-bit machine, 32-bit will not work! - test with the first sqlplus

create it if it doesn't exist

sudo vi /etc/launchd.conf 

and add the following to the file (with your own path!)

 setenv DYLD_LIBRARY_PATH /usr/oracle_instantClient64 

You need to reboot the system at this point so that launchd passes the path to apache to find the path or see if restarting the launch works, although I have the feeling that reboot your system anyway!

You must add "extension = oci8.so" in php.ini

 sudo vi /etc/php.ini 

If this file does not exist, copy the php.ini.default file

 sudo cp /etc/php.ini.default /etc/php.ini 

then add the specified extension, it will have a section with a lot of extensions down, put it somewhere somewhere

oci requires a symbolic link library, so

 sudo ln -s $DYLD_LIBRARY_PATH/libclntsh.dylib.10.1 $DYLD_LIBRARY_PATH/libclntsh.dylib 

There is also some wierd hard-coded library link in oracle binaries, so fix that

 mkdir -p /b/227/rdbms/ 

He is only looking for oracle libraries, so link it

 ln -s /usr/oracle_instantClient64/ /b/227/rdbms/lib 

now install oci8 from the pear repository. If you installed the osx 10.6 snow leopard without an update, you may have problems with the pear and club. If so, you need to install the pear first. see https://discussions.apple.com/thread/2602597?start=0&tstart=0

 sudo pecl install oci8 

TIP: do not use autodetect, specify the instantclient path when it asks you.

 instantclient,/usr/oracle_instantClient64 

restart apache

 sudo apachectl graceful 

by going to the URL in the browser or you can call the file directly on the command line

 php index.php 

thats it use the following as a test file.

 <?php $dbHost = "localhostOrDatabaseURL"; $dbHostPort="1521"; $dbServiceName = "servicename"; $usr = "username"; $pswd = "password"; $dbConnStr = "(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP) (HOST=".$dbHost.")(PORT=".$dbHostPort.")) (CONNECT_DATA=(SERVICE_NAME=".$dbServiceName.")))"; if(!$dbConn = oci_connect($usr,$pswd,$dbConnStr)){ $err = oci_error(); trigger_error('Could not establish a connection: ' . $err['message'], E_USER_ERROR); }; $strSQL = "SELECT SYSDATE FROM DUAL"; $stmt = oci_parse($dbConn,$strSQL); if ( ! oci_execute($stmt) ){ $err = oci_error($stmt); trigger_error('Query failed: ' . $err['message'], E_USER_ERROR); }; while(oci_fetch($stmt)){ $rslt = oci_result($stmt, 1); print "<h3>query returned: ".$rslt."</h3>"; } ?> 
+1
source

I don’t know the Mac specifically, nor PHP, but you usually need to install Oracle Client tools (Instant Client).

http://www.oracle.com/technology/tech/oci/instantclient/index.html

After installation, you modify the TNSNAMES.ORA file to specify the server name and instance of the Oracle database.

Then you can use the material to connect to the PHP database (sorry) to create a connection and run your SQL queries.

Use the SQL * PLUS client to test the connection:

t

 c:> SQLPLUS CONNECT scott/ tiger@mydatabase 

If TNSNAMES.ORA is correct, you should get a connection, or at least "username / password is incorrect", which proves that you got a connection to an Oracle instance.

If you receive TNS-12521 (?) Errors, then your TNSNAMES.ORA is incorrect.

0
source

Connecting to the oracle database should not be a problem with the oci interface, for example using oci_connect ().

Other examples: http://php.net/manual/en/oci8.setup.php

But I don't understand what the MAC OS X note means - are you using local Apache?

Hope this helps, Bastian

0
source

Source: https://habr.com/ru/post/1276828/


All Articles