PHP Classes
elePHPant
Icontem

File: example.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of JImmy Bo  >  Bobo PHP DB Class  >  example.php  >  Download  
File: example.php
Role: Example script
Content type: text/plain
Description: PHP Simple Database Class Usage Example
Class: Bobo PHP DB Class
Simple MySQL database class
Author: By
Last change: added example: $db->insert_from_array($table, $arr)
added example: $db->update_from_array($table, $arr, $extra);
Date: 1 year ago
Size: 2,219 bytes
 

Contents

Class file image Download
<?php
   
include_once('inc.config.php');
   
// if you like this class please rate it on
    // http://www.phpclasses.org/package/5283-PHP-Simple-MySQL-database-access-wrapper.html#ratings
    // ... and/or visit http://insidefame.com
   
    // not necessary but I put it in so you know it exists
   
$db->set_contype(0); # 0 = default (regular), 1 = peristent, 2 = persistent with compression, 3 = regular with compression
   
   
    // $db->q // insert or update
   
$sql = "INSERT INTO tablename (url, email) VALUES ('http://insidefame.com', 'user@email.com') ";
   
$id = $db->q($sql);
   
   
   
   
// $db->row // fetch a single row
   
$sql = "SELECT url, email FROM tablename";
   
$data = $db->r($sql);
   
# $data["url"] would equal 'http://insidefame.com'
    # $data["email"] would equal 'user@email.com'
   
   
   
    // $db->get // fetch an array
   
$sql = "SELECT url, email FROM tablename";
   
$rows = $db->get($sql);
   
# would return an array of multiple rows which you could traverse as such...
   
if(is_array($rows))
    {
        foreach(
$rows as $row)
        {
           
# $row["url"] would equal 'http://insidefame.com'
            # $row["email"] would equal 'user@email.com'
       
}
    }
   

   
# NEW!
   
    // $db->insert_from_array($table, $arr) // insert from an array
   
$table = 'tblorderpcs';
   
$arr = array (
           
"order_id" => $jobid,
           
"pcs_name" => $sname,
           
"pcs_qty" => $sqty,
           
"pcs_pn" => $spn,
           
"pcs_estimate" => $sest,
           
"pcs_memo" => $smemo,
           
"ship_id" => $ship_id,
           
"pcs_tstamp" => $time
       
);
   
$id = $db->insert_from_array($table, $arr);
   

   
// $db->update_from_array($table, $arr, $extra); // update from an array
   
$table = 'tblorderpcs';
   
$extra = "WHERE jID = $subjobid LIMIT 1";
   
$arr = array (
           
"pcs_name" => $sname,
           
"pcs_qty" => $sqty,
           
"pcs_pn" => $spn,
           
"pcs_estimate" => $sest,
           
"pcs_memo" => $smemo,
           
"ship_id" => $ship_id,
           
"pcs_made" => $smade,
           
"pcs_wasted"=> $swasted,
           
"pcs_ppu" => $sppu
       
);
       
    return
$db->update_from_array($table, $arr, $extra);

   
   
   
   
// you can force close the connection by calling. Not necessary
    // and if you perform another query after this it will automagically
    // reopen the connection.
   
$db->close();
?>