<?php
// Example usage of database.class.php (Uses MySQL) // Author: Alan Blockley <alan dot blockley at gmail dot com>
require('classes/database.class.php'); $db=new database("mysql","localhost","Friends","db_user","db_password");
$app_config['debug'] = 0;
if ($app_config['debug']) { $db->debug_mode(); }
// sets SQL statement and then query $sql = "SELECT * FROM addressbook"; $db->query($sql);
printf("<table border=1>"); printf("<tr>");
// Displays the field names using the field_name function AND count_fields for ($i=0;$i<$db->count_fields();$i++) { printf("<td><b>%s</b></td>",$db->field_name($i)); }
printf("</tr>");
// Load the array with the current row and then output in order. while ($row = $db->get_row()) { printf("<tr>"); for ($i=0;$i<$db->count_fields();$i++) { printf("<td>%s</td>",$row[$i]); } printf("</tr>"); }
// Just confirm how many records and fields using count_rows and count_fields printf("<tr><td colspan=5>%s records, %s fields</td></tr>",$db->count_rows(),$db->count_fields()); printf("</table>"); $db->disconnect();
?>
|