PHP Classes

File: example

Recommend this page to a friend!
  Classes of Tofeeq ur Rehman   Object based MySQL   example   Download  
File: example
Role: Example script
Content type: text/plain
Description: Example
Class: Object based MySQL
Manipulate MySQL table records as objects
Author: By
Last change:
Date: 15 years ago
Size: 1,265 bytes
 

Contents

Class file image Download
<?php

// IMPLEMENTATION
define("DB_NAME", "temp1");
define("DB_HOST", "localhost");
define("DB_USER", "root");
define("DB_PASS", "root");

require_once(
"mysql.php");

/*
    If constants defined then no need to pass the arguments in mysql function
    other wise pass arguments in following order
    $db = new mysql(datbase_name, host, user_name, password);
*/

//$db = new mysql("test","localhost","root","root");
$db = new mysql();
//$db->debug = false;

/*
    INSERTION:
    assign variables to the row of db object and call insert method by passing table name as arg
*/
/*
    $db->row->no = 5;
    $db->row->class = '8th';
    $db->row->name = 'sami';
    $db->insert('table1');
    echo $db->row->id;
*/


// UPDATING TABLE

   
echo "<H3>Updating</H1>";
   
   
$db->row->no = 8;
   
$db->row->class = '6th';
   
$db->row->name = 'nomi';
   
//in case, condition based on primary key such as where id =4 then just enter the id no
   
$db->update("table1", 6);
   
//in case condition based on some other criteria then enter full criteria
    //$db->update("table1", "name='sami'");


//DATA FETCHING
echo "<H3>Data</H3>";
$sql = "select * from `table1`";
$db->query($sql);
while (
$db->next()) {
    echo
$db->row->id . "\t";
    echo
$db->row->no . "\t";
    echo
$db->row->class . "\t";
    echo
$db->row->name . "<br>";
}