Skip to content

Instantly share code, notes, and snippets.

@johnvilsack
Created December 8, 2011 18:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnvilsack/1447906 to your computer and use it in GitHub Desktop.
Save johnvilsack/1447906 to your computer and use it in GitHub Desktop.
<?php
include('db.class.php');
// Instantiate
$CRUD = new CRUD();
// Set Connection Vars
$CRUD->database = "mysql:dbname=sessions;host=localhost";
$CRUD->username = 'test';
$CRUD->password = 'test';
// CREATE
$insert = array(array('*FIELD*' => '*VALUE*', '*FIELD*' => '*VALUE*'));
$CRUD->InsertDB('*TABLES*', $insert);
// READ AS SIMPLE QUERY
$result = $CRUD->SelectDB('*TABLE*', '*FIELD*', '*VALUE*');
foreach ($result as $array)
{
echo $array['*FIELD*'] . ' = ' . $row['*FIELD*'] . '<br />';
}
// READ AS RAW QUERY
$select = $CRUD->SQLWithReturn('SELECT * FROM *FIELD*');
$result = $select->fetchAll(PDO::FETCH_ASSOC); // Get Associative Array
foreach ($result as $row)
{
foreach ($row as $key => $value)
{
echo $key . ' :: ' . $value . PHP_EOL;
}
}
// UPDATE
$CRUD->UpdateDB('*TABLE*', '*FIELDTOUPDATE*', '*VALUETOUPDATE*', '*TARGETFIELD*', '*TARGETVALUE*');
// UPDATE MULTIPLE
$sql = "UPDATE FIELD SET FIELD=?, FIELD=? WHERE FIELD=?";
$query = $CRUD->prepare($sql);
$query->execute(array($VAR1,$VAR2,$VAR3));
// DELETE
$delItem = $CRUD->DeleteDB('*TABLE*', '*FIELD*', '*VALUE*');
// SQL WITH RETURN
$array = $CRUD->SQLWithReturn('SQL QUERY HERE');
// SQL NO RETURN
$CRUD->SQLNoReturn('SQL QUERY HERE');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment