<?php
// Require the class
require_once('MySQL.php');
// Database info
require_once('db.php');
// Instantiate the MySQL Class
// Parameters: Database Host, Database User, Database Password, Database Name, Persistent Connection (true or false)
$mysql = new MySQL($dbHost,$dbUser,$dbPass,$dbName);
// Check to see if errors occured
if ($mysql->isError()) {
// Print the error message
die($mysql->getMessage());
}
// The SQL to execute
$sql = "SELECT field FROM table";
// Execute the query
$result = $mysql->query($sql);
// Check for errors
if (! $result) {
// Print the error message
die($mysql->getMessage());
}
// Loop through the rows using the fetch() method
// Parameters: [optional] fetch mode (FETCH_ARRAY , FETCH_ASSOC or FETCH_OBJECT)
while ($row = $result->fetch(FETCH_OBJECT)) {
echo $row->field.'<br />';
}
echo 'Rows: '.$result->numRows();
// Free the result in memory
$result->free();
// Close the connection
$mysql->close();
?>
|