PHP Classes

File: mysql_example.php

Recommend this page to a friend!
  Classes of Alan Blockley   database.class.php   mysql_example.php   Download  
File: mysql_example.php
Role: Example script
Content type: text/plain
Description: Example of class usage with MySQL
Class: database.class.php
Database abstraction to access multiple databases
Author: By
Last change:
Date: 16 years ago
Size: 1,072 bytes
 

Contents

Class file image Download
<?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();

?>