example of connecting to a database and fetching a row by using the function-oriented API

<?php
include_once(“DB/mysql.php”);

$dbh = db_connect(array($host,$user,$pass));
if (!$dbh){
die(“Cannot connect to database”);
}
db_select_db(array(“sampleDB”));
$sth = db_query(“SELECT * FROM sampleTable”, $dbh);
if (!$sth) {
die(“Cannot execute query”);
}
while ($row = db_fetch_row(array($sth))) {
echo $row[“firstname”];
echo $row[“lastname”];
}
db_free_result(array($sth));
db_close(array($dbh));
?>

 

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.