<?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(); ?>
|