|
Here's an example of querying Oracle through PHP:
//set up database connection
$strUser = "scott";
$strPwd = "tiger";
$strDB="(DESCRIPTION=
(ADDRESS_LIST=
(ADDRESS=(PROTOCOL=TCP)
(HOST=my.hostname.domain.com)(PORT=1521)
)
)
(CONNECT_DATA=(SERVICE_NAME=theservice))
)";
//login to database
$objDBConn = OCILogon($strUser, $strPwd, $strDB);
//test DB object
if($objDBConn){
//construct query string
$strSQL = "SELECT FIRST_NAME, LAST_NAME FROM PEOPLE.TBL_NAMES";
//parse query string
$objQuery = OCIParse($objDBConn, $strSQL);
//execute SQL statement
$objResult = OCIExecute($objQuery);
//test SQL statement result
if($objResult){
//loop through query result set
while(OCIFetch($objQuery)){
echo OCIResult($objQuery, "FIRST_NAME");
echo " ";
echo OCIResult($objQuery, "LAST_NAME");
echo "<br>";
}//end while
}else{
//error in query
$arrError = OCIError($objQuery);
}//end objResult if
}else{
//error in connection
$arrError = OCIError();
}//end objDBConn if
if(isset($arrError)){
echo "ERROR: ".$arrError['message'];
}
|