Created
December 8, 2011 18:16
-
-
Save johnvilsack/1447906 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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