. 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() { $db = mysql_connect(_DBSERVER, _DBUSERID, _DBPWD) or db_die_with_error(_MSGNoDBCon); mysql_select_db(_DBNAME) or db_die_with_error(_MSGChDB); return $db; } function db_own_connection($host, $port, $user, $pass, $dbname) { if($port != 0) $db = mysql_connect($host . ":" . $port, $user, $pass) or db_die_with_error(_MSGNoDBCon); else $db = mysql_connect($host, $user, $pass) or db_die_with_error(_MSGNoDBCon); mysql_select_db($dbname) or db_die_with_error(_MSGChDB); return $db; } /* * Executes the SQL. * /param db Database connection handle * /param cmdSQL SQL statement * * /return Resource handle */ function db_exec($db, $cmdSQL) { //echo "

" . $cmdSQL . "

"; $result = mysql_query($cmdSQL, $db) or db_die_with_error(_MSGInvQur); return $result; } /* * Executes the SQL. * /param res Rescource hanndle * * /return The number of rows in the result set. */ function db_num_rows($res) { $result = mysql_num_rows($res); return $result; } /* * 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) { $result = mysql_fetch_array($res); return $result; } /* * 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) { $result = mysql_fetch_array($result); return $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) { $result = mysql_result($res, 1, $res_name) or db_die_with_error(_MSGNoRes); return $result; } function db_close($db) { mysql_close($db) or db_die_with_error(_MSGNoDBHan); } 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 mysql_free_result($result); } function db_get_tables($dbCon, $dbName) { $query = "SHOW TABLES FROM " . $dbName; return mysql_query($query); } function db_errno() { return mysql_errno(); } function db_error() { return mysql_error(); } function db_die_with_error($MyErrorMsg) { $errdesc = mysql_error(); $errno = mysql_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 '%'; } ?>