Login   Register  
PHP Classes
elePHPant
Icontem

File: examples.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Kevin Cadman  >  Data Workings  >  examples.php  >  Download  
File: examples.php
Role: Example script
Content type: text/plain
Description: Example Usage
Class: Data Workings
Access database table records as objects
Author: By
Last change:
Date: 8 years ago
Size: 2,737 bytes
 

Contents

Class file image Download
<?php
require_once 'system.inc';

//By this stage, I assume you have a successfully established connection set up via PEAR's DB system. 
//I use the variable name $db to store the database object.

//If you don't know how to setup a database connection using PEAR, please consult http://pear.php.net.
//Further, install the PEAR DB Class and download the test documentation.

/*

//INSERT EXAMPLE:

//The following demonstrates how to insert a record. Basically, pass an array of columns and array of values 
//and the class will do the rest


$data = new dataW($db,"users");
$data->insert(array("fullname","username","password"),array("User Fullname","username","password"));

*/


/*

//SINGLE RECORD FETCH EXAMPLE:

//The following demonstrates how to retrieve a record directly via the primary key. It also demonstrates the update() function.

$data = new dataW($db,"users");
$data->get(42);
echo $data->username; //Will output 'username' value
$data->username = "new username";
$data->update(); //This function will update the database with the changes made to the class variables


*/

/*

//ALL RECORD FETCH EXAMPLE:

//The following demonstrates how to retrieve all records from the database, with ordering, without paging.
//Notice: You can add as many setOrder()'s as you like - they will be appended.

$data = new dataW($db,"users");
$data->setOrder("fullname","asc");
$data->setOrder("id","desc");
$data->query();
while($data->fetch()) {
    echo "Fullname: {$data->fullname}<br />";
    $data->fullname = "new fullname";
}


*/

/*

//MULTIPLE RECORD FETCH EXAMPLE:

//The following demonstrates how to retrieve multiple records with paging, a clause and ordering.

$data = new dataW($db,"users");
$data->setClause("id>0");
$data->setOrder("fullname","asc");
$data->setResultsPerPage(5);
$data->query();
while($data->fetch()) {
    echo "ID:{$data->id}, Fullname:{$data->fullname}<br />";
    //You are able to call update() and delete() within a fetch() loop.
}
echo $data->pagingHTML();
*/

/*

//MULTIPLE RECORD WITH JOINS FETCH EXAMPLE:

//The following demonstrates how to retrieve multiple records with paging and joining another table.

$data = new dataW($db,"users");
$data->setClause("users.id>0");
$data->setOrder("users.fullname","asc");
$data->setJoin("LEFT","leave","user_id","=","users","id");
$data->setResultsPerPage(5);
$data->query("*,users.id as user_id");
while($data->fetch()) {
    echo "ID:{$data->user_id}, Fullname:{$data->fullname}, Leave Status: {$data->status}<br />";
    //You are NOT able to call update() and delete() within a fetch() loop if you have ACTIVE JOINS in your table.
}
echo $data->pagingHTML();

*/
?>