PHP Script for Creating Database Table

Listing 1. The createTable.php script creates the Catalog database table in the OE Schema.

<?php 
$username='OE';
$password='password';

$db='(DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = ORCL)
    )
  )';

$connection = oci_connect($username, $password, $db);

if (!$connection) {
  $e = oci_error();  
  echo htmlentities($e['message']);
} 

$stmt = oci_parse($connection, "CREATE TABLE OE.Catalog(CatalogId VARCHAR(25) PRIMARY KEY, Journal VARCHAR(25), Publisher Varchar(25), Edition VARCHAR(25), Title Varchar(45), Author Varchar(25))");


if (!$stmt) {
  $e = oci_error($connection);
  echo htmlentities($e['message']);
} 

  
$r = oci_execute($stmt);
if (!$r) {
  $e = oci_error($stmt); 
  echo htmlentities($e['message']);
}else{

  echo $connection . " created table\n\n";
}

$sql = "INSERT INTO OE.Catalog VALUES('catalog1', 'Oracle Magazine',  'Oracle Publishing', 'Nov-Dec 2004', 'Database Resource Manager', 'Kimberly Floss')";

  $stmt = oci_parse($connection, $sql);


if (!$stmt) {
  $e = oci_error($connection);  
  echo htmlentities($e['message']);
} 

$r = oci_execute($stmt);
if (!$r) {
  $e = oci_error($stmt); 
  echo htmlentities($e['message']);
}else{

  echo $connection . " added a row\n\n";
}

$sql = "INSERT INTO OE.Catalog VALUES('catalog2', 'Oracle Magazine',   'Oracle Publishing', 'Nov-Dec 2004', 'From ADF UIX to JSF', 'Jonas Jacobi')";

  $stmt = oci_parse($connection, $sql);


if (!$stmt) {
  $e = oci_error($connection);  
  echo htmlentities($e['message']);
} 

$r = oci_execute($stmt);
if (!$r) {
  $e = oci_error($stmt); 
  echo htmlentities($e['message']);
}else{

  echo $connection . " added a row\n\n";
}

$sql = "INSERT INTO OE.Catalog VALUES('catalog3', 'Oracle Magazine',   'Oracle Publishing', 'March-April 2005', 'Starting with Oracle ADF ', 'Steve Muench')";

  $stmt = oci_parse($connection, $sql);


if (!$stmt) {
  $e = oci_error($connection);  
  echo htmlentities($e['message']);
} 
$r = oci_execute($stmt);
if (!$r) {
  $e = oci_error($stmt); 
  echo htmlentities($e['message']);
}else{

  echo $connection . " added a row\n\n";
}

?>