Login   Register  
PHP Classes
elePHPant
Icontem

File: DatabaseExample.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Geoff Foley  >  Database Abstraction Class  >  DatabaseExample.php  >  Download  
File: DatabaseExample.php
Role: Example script
Content type: text/plain
Description: Example usage
Class: Database Abstraction Class
MySQL database abstraction package
Author: By
Last change:
Date: 2009-09-14 14:44
Size: 1,118 bytes
 

Contents

Class file image Download
<?php
// Load the database class
// As a practice of efficiency, the folowing two lines could be placed
// in a 'global' include file so that this class would be available to
// every application where the 'global' include file was included,
// i.e. a global header.
require('database_class.php'); // If you're using the 'classloader.php' module you could omit this line
$database = new database('your_database_name');

// Example Usage
$database->query("SELECT * FROM table_name WHERE column_name = 'some_value'");
$num_rows $database->num_rows();
if (
$num_rows != 0) {
    while (
$row $database->fetch_query()) {
        
$var_1 $row['col_name_1'];
        
$var_2 $row['col_name_2'];
        
$var_3 $row['col_name_3'];
    }
    
// OR
    
while ($row $database->fetch_object()) {
        
$var_1 $row->col_name_1;
        
$var_2 $row->col_name_2;
        
$var_3 $row->col_name_3;
    }
}
$database->clean_results();

// Delete w/affected_rows
$database->delete("DELETE FROM table_name WHERE column_name = 'some_value'");
if(
$database->affected_rows() > 0) {
    
// Success!
}

$database->close();
?>