PHP Class Pommo_Db, poMMo

Show file Open project: soonick/poMMo

Public Properties

Property Type Description
$_database
$_debug
$_dieOnQuery
$_link
$_prefix name of database
$_result
$_results & not overwriting the loops conditional resultset)
$_safeSQL
$table array of tables. array_key = nickname, value = table name in DB

Public Methods

Method Description
Pommo_Db ( $username = NULL, $password = NULL, $database = NULL, $hostname = NULL, $tablePrefix = NULL, $compress, $secure )
affected ( $sql = NULL ) result.
close ( ) closes the mySql link & frees the resources
debug ( $val )
dieOnQuery ( $val )
getAll ( $sql = NULL, $type = 'assoc', $field = NULL ) if field is given, just that field #/name is added to the array.
getError ( )
getRows ( $sql = NULL, $enumerated = FALSE, $uniqueId = NULL ) * useful for stuff like; while ($row = $dbo->getRows($sql)) $config[$row['config_name']] = $row['config_value'];
lastId ( $sql = NULL ) returns the ID of the pkey from an INSERT Statement FALSE if bad result
prepare ( ) throwing a warning)
query ( $query, $row = NULL, $col = NULL ) query function.
records ( $sql = NULL ) saved result.

Method Details

Pommo_Db() public method

public Pommo_Db ( $username = NULL, $password = NULL, $database = NULL, $hostname = NULL, $tablePrefix = NULL, $compress, $secure )

affected() public method

result.
public affected ( $sql = NULL )

close() public method

closes the mySql link & frees the resources
public close ( )

debug() public method

public debug ( $val )

dieOnQuery() public method

public dieOnQuery ( $val )

getAll() public method

if field is given, just that field #/name is added to the array.
public getAll ( $sql = NULL, $type = 'assoc', $field = NULL )

getError() public method

public getError ( )

getRows() public method

* useful for stuff like; while ($row = $dbo->getRows($sql)) $config[$row['config_name']] = $row['config_value'];
public getRows ( $sql = NULL, $enumerated = FALSE, $uniqueId = NULL )

lastId() public method

returns the ID of the pkey from an INSERT Statement FALSE if bad result
public lastId ( $sql = NULL )

prepare() public method

throwing a warning)
public prepare ( )

query() public method

Returns true if the query was successful, or false if not*. * If $this->_dieOnQuery is set, a die() will be issued and the script halted. If _debug is set, the mysql_error will be appended to the die() call. _dieOnQuery is enabled by default. If query is called with numeric arguments, a specific field is returned. This is useful for SQL statements that return a single row, or multiple rows of a single column. ex. A] query($sql,3) -> returns 4th column of a resultset B] query($sql,0,2) -> returns the second column of the first row of a resultset. A is useful for a result set containing a single column, ie. "SELECT name FROM people"; Example invocations from partent script: $dbo = & Pommo::$_dbo; $dbo->dieOnQuery(TRUE); $dbo->debug(TRUE); $sql = "SOME SQL QUERY"; if ($DB->query($sql)) { while ($row = mysql_fetch_assoc($dbo->_result)) { echo $row[fieldname]; } } $dbo->dieOnQuery(FALSE); $firstname = $dbo->query(SELECT phone,name FROM users,0,2); if (!$firstname) { echo "INVALID QUERY"; } $numRowsInSet = $dbo->records() $numRecordsChanged = $dbo->affected() :: EXAMPLE OF ITERATING THROUGH A RESULT SET (ROWS) :: $sql = "SELECT name FROM users WHERE group='X'"; while ($row = $dbo->getRows($sql)) { $sql = "UPDATE name SET group='Y' WHERE config_name='".$row['name']."'"; if (!$dbo->query($sql)) die('Error updating group for '.$row['name']); } }
public query ( $query, $row = NULL, $col = NULL )

records() public method

saved result.
public records ( $sql = NULL )

Property Details

$_database public property

public $_database

$_debug public property

public $_debug

$_dieOnQuery public property

public $_dieOnQuery

$_prefix public property

name of database
public $_prefix

$_result public property

public $_result

$_results public property

& not overwriting the loops conditional resultset)
public $_results

$_safeSQL public property

public $_safeSQL

$table public property

array of tables. array_key = nickname, value = table name in DB
public $table