Login   Register  
PHP Classes
elePHPant
Icontem

File: mysql_example.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  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: 2007-10-22 09:15
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();

?>