Source for file sql.php
Documentation is available at sql.php
* SQL interface functions, return statuscodes as appropriate
* The SQL functions are encapsulated here to make it easier
* to keep track of them, particularly for porting to other databases. Encapsulation is
* done here with a functional interface not an object interface.
* @todo //TODO: work out why we didn't just use PEAR::DB and be done with it right from the beginning
* @author Stuart Prescott
* @copyright Copyright Stuart Prescott
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
* @subpackage FormsLibrary
/** Load ancillary functions */
require_once 'inc/typeinfo.php';
/** status codes for success/failure of database actions */
require_once('inc/statuscodes.php');
* run an sql query without returning data
* @param string $q the sql query, properly constructed and quoted
* @param boolean $fatal_sql db errors are fatal
* @return integer status from statuscodes
//preDump(debug_backtrace());
// returns from statuscodes
return STATUS_OK; // should this return the $sql handle?
* run an sql query and return the sql handle for further requests
* @param string $q the sql query, properly constructed and quoted
* @param boolean $fatal_sql db errors are fatal
* @return resource mysql query handle
function db_get($q, $fatal_sql=
0) {
//preDump(debug_backtrace());
// returns from statuscodes or a db handle
* run an sql query and return the single (or first) row returned
* @param string $q the sql query, properly constructed and quoted
* @param boolean $fatal_sql db errors are fatal
* @return mixed array if successful, false if error
$sql =
db_get($q, $fatal_sql);
* return the last insert ID from the database
* @return integer id (row number) of previous insert operation
* return the next row from a query
* @param resource db query handle
* @return array next row from query
* get the number of rows returned by a query
* @param resource db query handle
* @return integer number of rows
* echo the SQL query to the browser
* @param string $echo the sql query
* @param boolean $success query was successful
function echoSQL($echo, $success=
0) {
echo
"<div class='sql'>".
xssqw($echo, false)
.
($success ?
'<div>'.
T_('(successful)').
'</div>' :
'')
* echo the SQL query to the browser
* @param string $echo the sql query
* @param boolean $fatal die on error
if ($echo !=
'' &&
$echo) {
echo
"<div class='sql error'>".
xssqw($echo) .
"</div>";
echo
"<div class='sql error'>"
.
sprintf(T_("Ooops. Something went very wrong. Please send the following log information to <a href='mailto:%s'>your Bumblebee Administrator</a> along with a description of what you were doing and ask them to pass it on to the Bumblebee developers. Thanks!"), $conf->AdminEmail)
logmsg(1, "SQL ERROR=[$echo]");
die('<b>'.
T_('Fatal SQL error. Aborting.').
'</b>');
* construct and perform a simple SQL select
* @param string $table name of the table (will have TABLEPREFIX added to it
* @param mixed $key single column name or list of columns for the WHERE clause
* @param mixed $value single value or list of values for WHERE $key=$value
* @param boolean $fatal die on error
* @param boolean $countonly run a COUNT(*) query not a SELECT query
* @return mixed array if successful, false if error
* @global string prefix for tabl nname
function quickSQLSelect($table, $key, $value, $fatal=
1, $countonly=
0) {
foreach ($key as $k =>
$col) {
$where[] =
$col.
'='.
qw($value[$k]);
$q =
'SELECT '.
($countonly ?
'count(*)' :
'*')
.
' FROM '.
$TABLEPREFIX.
$table
.
(count($where) ?
' WHERE '.
join($where,' AND ') :
'')
.
' LIMIT 1'; // we only ever return one row from this func, so LIMIT the query.
* returns the current version of the database that is being talked to
* @return string database version
if (! $conf->status->database) return "unavailable";
* returns the name of the database software that is being talked to
* @return string database server software name
Documentation generated on Tue, 06 Mar 2007 10:02:00 +0000 by phpDocumentor 1.3.0