database.class.php
- a simple database abstraction class
database.class.php
abstracts MYSQL databases using native php PDO
database.class.php
allows the execution of any SQL query against a MYSQL database and returns any result set. It can be easily modified for databases other than MYSQL
The connection object is persistent within a database object
Query parameters are embedded into the query rather than bound to the query
Result sets are not cached within the database object
class Database Read/write data to mysql database, uses PDO No external dependencies Sql staements dont have a ";" terminator Constructor for this database connection $dh or DIE = new Database(dsn,username,password,[options() = null]) dsn for mysql = mysql:host=localhost;dbname=testdb dsn for sqlite = sqlite2:/opt/databases/mydb.sq2 Execute SQL (INSERT, UPDATE, DELETE, etc) on database count or FALSE = dh->putQuery(sql) Execute SELECT on database, return multiple rows with multiple columns array of row objects or FALSE = dh->getRange(sql) Execute SELECT on database, return a single column single row cell mixed or FALSE = dh->getCell(sql) Execute SELECT on database, return single row of multiple columns row object or FALSE = dh->getRow(sql) Execute SELECT on database, return a single column of multiple rows array of mixed or FALSE = dh->getColumn(sql) Return sql from last executed query for debugging $string = dh->lastSql() last sql string is sticky Quote and escape (if required) any string or number quoted string = dh->quoteArg(argument) Begin transaction on database null = dh->beginTransaction() Commit transaction on database null = dh->commitTransaction() Rollback transaction on database null = dh->rollbackTransaction() Get id of last INSERT integer = dh->lastInsertId()
None
John Bartlett
johnb@thesolution.com.au
Requires php PDO module