PHP Classes

File: index.php

Recommend this page to a friend!
  Classes of Nemeth Zoltan   IDatabase class   index.php   Download  
File: index.php
Role: Example script
Content type: text/plain
Description: Example script fro IDatabase class use
Class: IDatabase class
MySQL Database access wrapper using MySQLi
Author: By
Last change:
Date: 10 years ago
Size: 1,144 bytes
 

Contents

Class file image Download
<pre>
<?php
include_once 'IDatabase.class.php';
include_once
'EException.class.php';
/*
 * Example file for IDatabase class
 */

// Create database connection or die
$db = IDatabase::getSingleton();
echo
"Connection successful.";

print
"<p>SELECT ALL ROWS</p>";
// Get all data in an array from the sample table
$data = $db->select("SELECT * FROM sample");
// Print data
print_r($data);
print
"<p>UPDATE ALL ROWS</p>";
// Update all row counter +1
$updatedRows = $db->update("UPDATE sample SET counter=counter+1;");
$data = $db->select("SELECT * FROM sample");
// Print data
print "Affected rows: ".$updatedRows."<br />";
print_r($data);
print
"<p>INSERT RANDOM tester AND print last query string</p>";
$insertID = $db->insertA(array(
 
'table' => 'sample',
 
'name' => 'tester'.mt_rand(100,10000),
 
'counter' => '0',
));
print
"Inserted ID: ".$insertID."<br />Insert Query: ".$db->getLastQuery();
print
"<p>DELETE last inserted row (id: ".$insertID.")</p>";
$deletedRows = $db->delete("DELETE FROM sample WHERE id=".$insertID);
print
"Query: ".$db->getLastQuery()."Affected rows: ".$deletedRows;
?>
</pre>