DB is the missing database helper class for PHP.
DB allows you to insert, select, update, and delete from a mysql database using arrays.
Super lightweight. Super easy.
Start using DB in three easy steps:
- Download the DB.class.php and DB.config.php
- Modify DB.config.php to connect to your MySQL server
- Include DB.config.php in your php file
You now have the $db object you can use to start talking to your database.
Simple Insert
$db->insertRow("cats", array("name" => "Fluffy", "breed" => "Siamese", "age" => 2));
$db->insertRow("cats", array("name" => "Charlie", "breed" => "Siamese", "age" => 3));
Simple Select Single Row
$cat = $db->selectRow("cats", array("name" => "Fluffy"));
echo $cat["age"];
Simple Select Multiple Rows
$cats = $db->selectRows("cats", array("breed" => "Siamese"));
foreach ($cats as $cat)
echo $cat["name"];
Simple Update Row
$cats = $db->updateRow("cats", array("breed" => "Bengal"), array("name" => "Fluffy"));
Simple Delete Row
$cats = $db->deleteRow("cats", array("name" => "Fluffy"));
Increment Field
$db->incrementValue("cats", "age", array("name" => "Fluffy"));
Sum Rows
$sum = $db->sumRows("cats", "age", array());
echo "Total cat years: " . $sum;
Search Rows
$cats = $db->searchRows("cats", array("name" => "Fluf"));
Select, Modify, Update
$cat = $db->selectRow("cats", array("name" => "Fluffy"));
$cat['age'] = 3;
$db->updateRow("cats", array("name" => "Fluffy"), $cat);
Advanced Select
$db->select("cats", array("breed" => "Siamese"), "age", 2);
Insert From Post
unset($_POST["submit"]);
$db->insertRow("cats", $_POST);