. See AUTHORS to learn who helped make
it become a reality.
*/#### #### #### #### #### #### #### #### #### ####
/*
* This file contains the function for database connection
* via mysql
*/
/*! \addtogroup DB Converter
*
* All converter functions using to prepare things to work with database queries
* use the prefix "dbc_"
* @{
*/
/*
* Generate the tags for a time argument using in a sql statment
* \param timestamp which need tags
* \return timestamp_with_tags returns the timestamp with tags in the nesessary format
*/
function dbc_sql_timeformat($times)
{
return "'".date("Y-m-d H:i:s", $times)."'";
}
/*! @} */
/*
* Database driver
*/
/*
* Attempts to establish a connection to the database.
* /return the connection handle if the connection was successful, NULL if the connection was unsuccessful.
*/
function db_connection()
{
return odbc_connect(_DBNAME, _DBUSERID, _DBPWD, SQL_CUR_USE_ODBC);
}
function db_own_connection($host, $port, $user, $pass, $dbname)
{
$db = odbc_connect($dbname, $user, $pass, SQL_CUR_USE_ODBC) or db_die_with_error(_MSGNoDBCon);
return $db;
}
/*
* Executes the SQL.
* /param db Database connection handle
* /param cmdSQL SQL statement
*
* /return Resource handle
*/
function db_exec($db, $cmdSQL)
{
// echo "
" . $cmdSQL . "
";
return odbc_exec($db, $cmdSQL);
}
/*
* Executes the SQL.
* /param res Rescource hanndle
*
* /return The number of rows in the result set.
*/
function db_num_rows($res)
{
return odbc_num_rows($res);
}
/*
* Fetch a result row as an associative array, a numeric array, or both.
* /param res Rescource hanndle
*
* /return Returns an array that corresponds to the fetched row, or FALSE if there are no more rows.
*/
function db_fetch_array($res)
{
return odbc_fetch_array($res);
}
/*
* db_fetch_singleresult is need in ODBC mode, so db_fetch_singleresult and db_fetch_array
* are the same in MySQL
*/
function db_fetch_singleresult($result)
{
return odbc_fetch_array($result);
}
/*
* Get the result data.
* /param res Rescource hanndle
* /param res_name either be an integer containing the column number of the field you want;
or it can be a string containing the name of the field. For example:
*
* /return the contents of one cell from the result set.
*/
function db_result($res, $res_name)
{
return odbc_result($res, 1, $res_name);
}
function db_close($db)
{
odbc_close($db);
}
function db_num_count($cmdSQLwhere_part)
{
return 'SELECT COUNT(*) AS num FROM ' . _DBTABLENAME . $cmdSQLwhere_part;
}
/*
* fetch a result row as an a numeric array
* the array points to the first data record you want to display
* at current page. You need it for paging.
*/
function db_exec_limit($db, $cmdSQLfirst_part, $cmdSQLmain_part, $cmdSQLwhere_part, $limitlower, $perpage, $order)
{
$cmdSQL = $cmdSQLfirst_part . $cmdSQLmain_part . $cmdSQLwhere_part . " limit ".($limitlower-1)."," . $perpage;
return db_exec($db, $cmdSQL);
}
function db_free_result($result)
{
return odbc_free_result($result);
}
function db_get_tables($dbCon, $dbName)
{
return odbc_tables($dbCon);
}
function db_errno()
{
return odbc_error();
}
function db_error()
{
return odbc_errormsg();
}
function db_die_with_error($MyErrorMsg)
{
$errdesc = odbc_error();
$errno = odbc_errno();
$errormsg="
Database error: $MyErrorMsg
";
$errormsg.="mysql error: $errdesc
";
$errormsg.="mysql error number: $errno
";
$errormsg.="Date: ".date("d.m.Y @ H:i")."
";
$errormsg.="Script: ".getenv("REQUEST_URI")."
";
$errormsg.="Referer: ".getenv("HTTP_REFERER")."
";
echo $errormsg;
exit;
}
/*
* Returns what wildcut the database use (e.g. %, *, ...)
*/
function db_get_wildcut()
{
return '%';
}
?>