By : parkerj Published On Sunday, December 02, 2012, 01:44 In PHP Scripts
This small class will save you time by providing CRUD methods for quickly building SQL query statements. This can be used and integrated into any existing project with ease. Also, it is great at handling exceptions when SQL errors are produced.
require('class.db.php');
// Create
$bind = array( ":id" => $_POST['user_id'], ":user" => $_POST['username']);
db::inst()->insert( "users", array(":id", ":user"), 'user_id, username', $bind );
// Read
db::inst()->init( "SELECT * FROM users ORDER BY last_name" );
// Update
$bind = array( ":signature" => $_POST['signature'] );
db::inst()->update( 'users', array('signature' => ":signature"), array('username',$_SESSION['username']), $bind );
// Delete
$bind = array(":id" => $_POST['pID']);
db::inst()->delete( "posts", "postID = :id", $bind );