<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>oci_pdo_empT1S.php</title>
</head>
oci_pdo_empT2.php
<body>
<?php
// oci_pdo_empT2.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";
/*** SQL SELECT statement ***/
$sql = "SELECT e.eid,e.info.fname,e.info.lname, e.info.address from
EMPT1 e";
$count="";
// uses pdo and object table
/*** fetch into an PDOStatement object ***/
$stmt = $conn->prepare($sql);
$stmt->execute();
//$count = $stmt->rowCount();// DOES NOT WORK
$count = "";
echo "<br/>select query worked";
/*** loop over the object directly ***/
echo "<table border='1'>\n";
while($row = $stmt->fetch(PDO::FETCH_OBJ))
{
$count++;
echo "<tr>\n";
foreach ($row as $item) {
echo "<td class='td2'>".($item !== null ? htmlentities($item,
ENT_QUOTES):" ")."</td>\n";
} //foreach ends
}
//
echo "</table>\n";
//
//echo " no of rows : ". oci_num_rows($stmt);
echo "no.of rows :".$count;
/*** close the database connection ***/
$conn= null;
//
}catch(PDOException $e){
echo ($e->getMessage());
}
echo "bye";
?>
</body>
</html>