Wallogit.com
2017 © Pedro Peláez
Simple MySQL db wrapper functions using PDO
This is a simple class for providing a simple API to the PDO MySQL database driver., (*1)
It relies on all tables in your database having a column called id which
is typically a serial type (bigint(20) unsigned auto_increment). This
column is used to select individual records within a table., (*2)
Create an object:, (*3)
$db = new \Majenkotech\DB("username", "password", "hostname", "database");, (*4)
Execute a query with optional embedded arguments:, (*5)
$q = $db->query("SELECT name,size FROM something WHERE foo=:bar AND baz=:fod", array( "bar" => 23, "fod" => "beep" ) );, (*6)
Use $db->nextRecord($q) to get successive record objects:, (*7)
while ($r = $db->nextRecord($q)) { print "$r->name is $r->size\n"; }, (*8)
Insert a new record into a table:, (*9)
$id = $db->insert("tablename", array( "field1" => "value", "field2" => value, ... etc ... ));, (*10)
Get ID of last inserted record:, (*11)
$id = $db->id();, (*12)
Update a record in a table:, (*13)
$db->update("table", $id, array( "field1" => "value", "field2" => value, ... etc ... ));, (*14)
Select a record by ID:, (*15)
$r = $db->select("tablename", $id);, (*16)
Set a single value in a record in a table:, (*17)
$db->set("table", $id, "field", "value");, (*18)