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']);
}
}