/**
* A working example of how to query the Oracle 9i database. Just rename
* this with a php extension and fill in the appropriate DB username,
* password, and server below.
*
* This code was placed in the public domain by its author, Niek Sanders, on
* October 5, 2004.
*
*/
// Database access
$dbuser = 'dbUserAccountName';
$dbpass = 'dbUserPasswordName';
$dbserver = 'dbServerName';
// Connect to database
$conn = ora_logon( "$dbuser/$dbpass", $dbserver );
// Open a cursor
$cursor = ora_open( $conn );
// SQL query we are running
$usersql = "SELECT * FROM tab";
// Bind our query to cursor
ora_parse( $cursor, $usersql );
// Execute cursor
ora_exec( $cursor );
// Array caching the results for each row in query
$rowResult = array();
// Grab each row into array, print out all the returned columns
while ( ora_fetch_into( $cursor, &$rowResult,
ORA_FETCHINTO_NULLS | ORA_FETCHINTO_ASSOC ) ) {
// Quick and dirty print_r method
// echo 'Row: ', print_r( $rowResult ), "
\n";
// Fine-tuned for_each method
foreach ( $rowResult as $colName => $colValue ) {
echo $colName, ' => ', $colValue, "
\n";
}
echo "
\n";
}
// Display total number of rows we fetched from cursor so far
// Note: this gives number of rows fetched, not number of rows in result.
echo '
Number of rows fetched from cursor so far: ',
ora_numrows( $cursor ), '
';
// Close cursor
ora_close( $cursor );
// Close session
ora_logoff( $conn );
?>
Done!