Login   Register  
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 stuartc  >  CMC Database Classes  >  example.php  >  Download  
File: example.php
Role: Example script
Content type: text/plain
Description: example of how to use all methods in the classes
Class: CMC Database Classes
Select, Insert, Update, Delete with MySQL
Author: By
Last change: Updated to reflect, class changes.
Date: 2002-10-21 16:55
Size: 2,041 bytes
 

Contents

Class file image Download
<?php
// required classes
include_once 'cmc_db_config.inc.php'// configuration class (parent)
include_once 'cmc_db_recordset.inc.php'// recordset class (sub)
include_once 'cmc_db_execute.inc.php'// execute class (sub)

// *******************************************************
// SQL EXECUTION
// *******************************************************
// - use of: db_execute - parent = db_config)
$db_exec = new db_execute();
$db_exec->set_host("localhost");
$db_exec->set_user("root");
$db_exec->set_pass("database_password");
$db_exec->set_database("database_name");
$db_exec->get_connect();

// - INSERT
$sql "INSERT INTO table VALUES (NULL, 'Madeup')";
if(
$db_exec->db_set_execute($sql)) {
    echo 
"insert success !!";
} else {
    echo 
"insert failed !!";
    echo 
$db_exec->db_get_error()."<br>";
}

// - DELETE
$sql "DELETE FROM table WHERE LastName = 'Person'";
if(
$db_exec->db_set_execute($sql)) {
    echo 
"delete success !!";
} else {
    echo 
"delete failed !!";
    echo 
$db_exec->db_get_error()."<br>";
}

// - UPDATE
$sql "UPDATE table SET LastName = 'new' WHERE LastName = 'Person'";
if(
$db_exec->db_set_execute($sql)) {
    echo 
"update success !!";
} else {
    echo 
"update failed !!";
    echo 
$db_exec->db_get_error()."<br>";
}



// *******************************************************
// SQL RECORDSETS
// *********************************************************
// - use of: db_recordset - (parent = db_config)
$db_sel = new db_execute();
$db_sel->set_host("localhost");
$db_sel->set_user("root");
$db_sel->set_pass("database_password");
$db_sel->set_database("database_name");
$db_sel->get_connect();


// - RECORDSET (SQL SELECT)
$sql "SELECT ID, FirstName, LastName FROM table";
$db_sel->db_set_recordset($sql"3"); // sql and num of elements to return
$count $db_sel->db_get_count();
$result $db_sel->db_get_recordset();
// loop the rows returned
for($r=0$r<$count$r++){
    echo 
$result[$r][0]." ".$result[$r][1]." ".$result[$r][2]."<br>";
}
?>