<html>
<head>
<title>Test PHP Database Connection to Oracle</title>
</head>
<body>
<h1>Test PHP Database Connection to Oracle</h1>
<br><br>
<?php
$host = 'workshop.sps.nyu.edu:1521';
// $host = 'localhost';
$db = 'ORCL';
$user = 'demo';
$pswd = 'demo';
// Connect to MySql database server -------------------------------------
$host_db = $host . '/' . $db;
$connect = oci_connect($user,$pswd,$host_db);
if (! $connect) {
$error = oci_error();
die('Could not connect: ' . $error['message']);
}
print("<b>Connected to DB server on: $host</b><br>");
print("<b>Database selected: $db</b><br><br>");
// perform select query -------------------------------------------------
$stmt = oci_parse($connect, 'select fname, lname, ssn from student');
if (! $stmt) {
$error = oci_error();
die('Could not parse statement: ' . $error['message']);
}
$result = oci_execute($stmt, OCI_DEFAULT);
if (! $result) {
$error = oci_error();
die('Could not execute query: ' . $error['message']);
}
while ($row = oci_fetch_assoc($stmt)) {
echo $row['FNAME'],' ',$row['LNAME'],' ',$row['SSN'],'<br>';
}
// release resources ----------------------------------------------------
oci_free_statement($stmt);
oci_close($connect);
?>
<?php include "../include.php"; ?> <!-- hyperlink to see the code -->
</body>
</html>