majenkotech / dbwrapper
Simple MySQL db wrapper functions using PDO
Installs: 48
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/majenkotech/dbwrapper
This package is not auto-updated.
Last update: 2025-10-26 10:31:45 UTC
README
This is a simple class for providing a simple API to the PDO MySQL database driver.
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.
Usage
- 
Create an object:
$db = new \Majenkotech\DB("username", "password", "hostname", "database");
 - 
Execute a query with optional embedded arguments:
$q = $db->query("SELECT name,size FROM something WHERE foo=:bar AND baz=:fod", array( "bar" => 23, "fod" => "beep" ) );
 - 
Use
$db->nextRecord($q)to get successive record objects:while ($r = $db->nextRecord($q)) { print "$r->name is $r->size\n"; }
 
Other useful functions
- 
Insert a new record into a table:
$id = $db->insert("tablename", array( "field1" => "value", "field2" => value, ... etc ... ));
 - 
Get ID of last inserted record:
$id = $db->id();
 - 
Update a record in a table:
$db->update("table", $id, array( "field1" => "value", "field2" => value, ... etc ... ));
 - 
Select a record by ID:
$r = $db->select("tablename", $id);
 - 
Set a single value in a record in a table:
$db->set("table", $id, "field", "value");