oci_pdo_empT1.htm
Objectives:
  • Connection like using TNSNAMES.ORA
  • new PDO connection:
    • $conn = new PDO("oci:dbname=".$tns,$db_username,$db_password);
      $stmt = $conn->prepare($sql);

      $stmt->execute();
      echo "<br/>select query worked";
      $count = $stmt->rowCount();// did not work
  • Use of PDO:FETCH: $stmt->fetch(PDO::FETCH_OBJ)
  • SOURCE CODE :  oci_pdo_empT1.txt

Object saved @

Now create a table:

PHP script

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>New Page 1</title>
</head>
<body>
<?php
// oci_pdo_empT1.php
$tns = "
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = orcl.gateway.2wire.net))
)
";
$db_username = "scott"; $db_password = "Son";
try{
$conn = new PDO("oci:dbname=".$tns,$db_username,$db_password);
echo "Hurrah HO!!! Oacle pdo extension is working";
/*** The SQL SELECT statement ***/
$sql = "SELECT e.eid,e.info.fname,e.info.lname, e.info.address from EMPT1 e";
// uses pdo and object table
/*** fetch into an PDOStatement object ***/
$stmt = $conn->prepare($sql);
$stmt->execute();
echo "<br/>select query worked";
$count = $stmt->rowCount();// did not work
echo "<br/>row count" . $count;
/*** echo number of columns ***/
/*** loop over the object directly ***/
echo "<table border='1'>\n";
while($row = $stmt->fetch(PDO::FETCH_OBJ)) {
echo "<tr>\n";
foreach ($row as $item) {
echo "<td class='td2'>".($item !== null ? htmlentities($item, ENT_QUOTES):"&nbsp;")."</td>\n";
} //foreach ends
}
//
echo "</table>\n";
//
//echo " no of rows : ". oci_num_rows($stmt);
/*** close the database connection ***/
$conn= null;
//
}catch(PDOException $e){
echo ($e->getMessage());
}
echo "bye";
?>
</body>
&nbsp;</html>

Runtime :