Oracle connection

How to start with Linux

Basic example of an Oracle connection using oci_connect on Linux.

/* Connect to an Oracle database */

/* Configuration info */
$dbuser='some_user';
$pass='some_password';
 
// Setup the connection
$conn = oci_connect("$dbuser", "$pass", "//localhost/SID");
 
// Show error in case of no connection
if (!$conn) {
   $m = oci_error();
   echo $m['message'], "\n";
   exit;
}

// Set query
$query = oci_parse($conn, "select * from users");
oci_execute($query);
 
// Show results
while($row=oci_fetch_array($query)) {
        echo $row['firstname']." ".$row['lastname']. "\n"; // Show only the first and last names.
}  
 
// Close the Oracle connection
oci_close($conn);