How to Connect to Remote Oracle Database through PHP?

Connect to an Oracle database using php

  • I need to connect to an Oracle database server with system identifier PROD, using the login "scott" and password "tiger." Can anyone help

  • Answer:

    You could use http://php.net/manual/en/book.pdo.php to connect to oracle. That way you can also easily change between different types of databases without changes to your code, making it very portable. But note that the Oracle driver for PDO is marked as experimental so it might be changed with later releases of PHP. Note* Never tested PDO for oracle myself, but it's brilliant for other types of databases and makes you able to switch between different databases easily.

Poonam Bhatt at Stack Overflow Visit the source

Was this solution helpful to you?

Other answers

this is sample extract from http://www.orafaq.com/wiki/Tnsnames.ora: MYSERVICE = (DESCRIPTION = (ADDRESS = (PROTOCOL = tcp)(HOST = database_hostname_or_ip.com)(PORT = 1521)) (CONNECT_DATA = (SERVICE_NAME=myservice))) This is sample script to connect and execute query: $oracledb["host"] = "MYSERVICE"; # service name in the tnsnames.ora file $oracledb["user"] = "myuser"; # username $oracledb["pass"] = "mypass"; # password $oracledb["library"] = "OCI"; $connect_id = ocilogon($oracledb["user"], $oracledb["pass"], $oracledb["host"]); $query = "SELECT * FROM table"; $statement = ociparse($connect_id, $query); ociexecute($statement); $result = array(); while(ocifetchinto($statement, $tmp, OCI_ASSOC + OCI_RETURN_NULLS + OCI_RETURN_LOBS)) { array_push($result, $tmp); } ocifreestatement($statement); var_dump($result); # result is here

Lyuben

Use PHP function http://php.net/manual/en/function.oci-connect.php to connecto to oracle db

Shameer

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.