开发者

Connect to an Oracle database using php [closed]

开发者_如何学JAVA It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 10 years ago.

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

Can anyone help


this is sample extract from 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


You could use PDO 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.


Use PHP function oci_connect to connecto to oracle db

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜