сряда, април 08, 2009

PHP + Oracle


Example extract from TNSNAMES.ORA:

MYSERVICE =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = tcp)(HOST = database_hostname_or_ip.com)(PORT = 1521))
(CONNECT_DATA =
(SERVICE_NAME=myservice)))

PHP script:

$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

Няма коментари: