} // END - if
// SQL queries
-function SQL_QUERY ($sqlString, $F, $L, $enableCodes = TRUE) {
+function sqlQuery ($sqlString, $F, $L, $enableCodes = TRUE) {
// Is there cache?
if (!isset($GLOBALS[__FUNCTION__][$sqlString])) {
//* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Called: ' . $sqlString);
basename($F),
$L
));
- } elseif (!SQL_IS_LINK_UP()) {
+ } elseif (!isSqlLinkUp()) {
// We should not quietly ignore this
reportBug(__FUNCTION__, __LINE__, sprintf("Cannot query database: sqlString=%s,file=%s,line=%s",
$sqlStringModified,
$sqlStringModified = str_replace(array(chr(9), PHP_EOL, chr(13)), array(' ', ' ', ' '), $sqlStringModified);
// Compile config entries out
- $sqlStringModified = SQL_PREPARE_SQL_STRING($sqlStringModified, $enableCodes);
+ $sqlStringModified = sqlPrepareQueryString($sqlStringModified, $enableCodes);
// Cache it and remember as last SQL query
$GLOBALS[__FUNCTION__][$sqlString] = $sqlStringModified;
$GLOBALS['last_sql'] = $sqlStringModified;
//* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Stored cache: ' . $sqlStringModified);
- } elseif (!SQL_IS_LINK_UP()) {
+ } elseif (!isSqlLinkUp()) {
// Link went down while using cached SQL
reportBug(__FUNCTION__, __LINE__, 'Link went down while using cached SQL: sqlString=' . $sqlString . ',F=' . basename($F) . ',L=' . $L . ',enableCodes=' . intval($enableCodes));
} else {
// Run SQL command
//* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'F=' . basename($F) . ',L=' . $L . ',sql=' . $GLOBALS['last_sql']);
- $result = mysql_query($GLOBALS['last_sql'], SQL_GET_LINK())
- or SQL_ERROR($F, $L, 'file='. basename($F) . ',line=' . $L . ':mysql_error()=' . mysql_error() . ',last_query=' . $GLOBALS['last_sql']);
+ $result = mysql_query($GLOBALS['last_sql'], getSqlLink())
+ or sqlError($F, $L, 'file='. basename($F) . ',line=' . $L . ':mysql_error()=' . mysql_error() . ',last_query=' . $GLOBALS['last_sql']);
//* DEBUG: */ logDebugMessage($F, $L, 'sql=' . $GLOBALS['last_sql'] . ',affected=' . SQL_AFFECTEDROWS() . ',numRows='.(is_resource($result) ? SQL_NUMROWS($result) : gettype($result)));
// Calculate query time
incrementConfigEntry('sql_count');
// Debug output
- if (SQL_DEBUG_ENABLED()) {
+ if (isSqlDebugEnabled()) {
// Is this the first call?
if (!isset($GLOBALS['sql_first_entry'])) {
// Write first entry
} // END - if
// Append debug line
- appendLineToFile(getCachePath() . 'mysql.log', basename($F) . '|LINE=' . $L . '|NUM=' . (is_resource($result) ? SQL_NUMROWS($result) : 'false') . '|AFFECTED=' . SQL_AFFECTEDROWS() . '|QUERYTIME:' . ($queryTime * 1000) . 'ms): ' . str_replace(array(chr(13), PHP_EOL), array('', ' '), $GLOBALS['last_sql']));
+ appendLineToFile(getCachePath() . 'mysql.log', basename($F) . '|LINE=' . $L . '|NUM=' . (is_resource($result) ? sqlNumRows($result) : 'false') . '|AFFECTED=' . sqlAffectedRows() . '|QUERYTIME:' . ($queryTime * 1000) . 'ms): ' . str_replace(array(chr(13), PHP_EOL), array('', ' '), $GLOBALS['last_sql']));
} // END - if
// Increment stats entry
}
// SQL num rows
-function SQL_NUMROWS ($resource) {
+function sqlNumRows ($resource) {
// Valid link resource?
- if (!SQL_IS_LINK_UP()) return FALSE;
+ if (!isSqlLinkUp()) return FALSE;
// Link is not up, no rows by default
$lines = FALSE;
}
// SQL affected rows
-function SQL_AFFECTEDROWS () {
+function sqlAffectedRows () {
// Valid link resource?
- if (!SQL_IS_LINK_UP()) return FALSE;
+ if (!isSqlLinkUp()) return FALSE;
// Get affected rows
- $lines = mysql_affected_rows(SQL_GET_LINK());
+ $lines = mysql_affected_rows(getSqlLink());
// Return it
return $lines;
}
// SQL fetch row
-function SQL_FETCHROW ($resource) {
+function sqlFetchRow ($resource) {
// Is $resource valid?
- if ((!is_resource($resource)) || (!SQL_IS_LINK_UP())) return FALSE;
+ if ((!is_resource($resource)) || (!isSqlLinkUp())) return FALSE;
// Fetch the data and return it
return mysql_fetch_row($resource);
}
// SQL fetch array
-function SQL_FETCHARRAY ($resource) {
+function sqlFetchArray ($resource) {
// Is $resource valid?
- if ((!is_resource($resource)) || (!SQL_IS_LINK_UP())) return FALSE;
+ if ((!is_resource($resource)) || (!isSqlLinkUp())) return FALSE;
// Load row as array from database
$row = mysql_fetch_assoc($resource);
}
// SQL result
-function SQL_RESULT ($resource, $row, $field = '0') {
+function sqlResult ($resource, $row, $field = '0') {
// Is $resource valid?
- if ((!is_resource($resource)) || (!SQL_IS_LINK_UP())) return FALSE;
+ if ((!is_resource($resource)) || (!isSqlLinkUp())) return FALSE;
// Run the result command
$result = mysql_result($resource, $row, $field);
}
// SQL connect
-function SQL_CONNECT ($host, $login, $password, $F, $L) {
+function sqlConnectToDatabase ($host, $login, $password, $F, $L) {
// Try to connect
- $linkResource = mysql_connect($host, $login, $password) or SQL_ERROR($F, $L, mysql_error());
+ $linkResource = mysql_connect($host, $login, $password) or sqlError($F, $L, mysql_error());
// Set the link resource
if (is_resource($linkResource)) {
/*
* A non-resource (boolean) may happen on installation phase which
* shall not be set here. Only valid link resources shall be set so
- * SQL_IS_LINK_UP() will only return 'true' if there is really a
+ * isSqlLinkUp() will only return 'true' if there is really a
* working database link.
*/
- SQL_SET_LINK(__FUNCTION__, __LINE__, $linkResource);
+ setSqlLink(__FUNCTION__, __LINE__, $linkResource);
// Init charsets (UTF-8 is default now)
- SQL_QUERY("SET
+ sqlQuery("SET
`character_set_results`='utf8',
`character_set_client`='utf8',
`character_set_connection`='utf8',
}
// SQL select database
-function SQL_SELECT_DB ($dbName, $F, $L) {
+function sqlSelectDatabase ($dbName, $F, $L) {
// Is there still a valid link? If not, skip it.
- if (!SQL_IS_LINK_UP()) return FALSE;
+ if (!isSqlLinkUp()) return FALSE;
// Return the result
//* DEBUG: */ logDebugMessage($F . ':' . __FUNCTION__, $L . ':' . __LINE__, 'Selecting database ' . $dbName);
- return mysql_select_db($dbName, SQL_GET_LINK()) or SQL_ERROR($F, $L, mysql_error());
+ return mysql_select_db($dbName, getSqlLink()) or sqlError($F, $L, mysql_error());
}
// SQL close link
-function SQL_CLOSE ($F, $L) {
+function sqlCloseLink ($F, $L) {
// Is the link up?
- if (!SQL_IS_LINK_UP()) {
+ if (!isSqlLinkUp()) {
// Skip double close
//* DEBUG: */ logDebugMessage($F . ':' . __FUNCTION__, $L . ':' . __LINE__, 'Called but no link is open.');
return FALSE;
} // END - if
// Close database link and forget the link
- $close = mysql_close(SQL_GET_LINK()) or SQL_ERROR($F . ':' . __FUNCTION__, $L . ':' . __LINE__, mysql_error());
+ $close = mysql_close(getSqlLink()) or sqlError($F . ':' . __FUNCTION__, $L . ':' . __LINE__, mysql_error());
// Close link in this layer
unsetSqlLinkUp(__FUNCTION__, __LINE__);
}
// SQL free result
-function SQL_FREERESULT ($resource) {
- if ((!is_resource($resource)) || (!SQL_IS_LINK_UP())) {
+function sqlFreeResult ($resource) {
+ if ((!is_resource($resource)) || (!isSqlLinkUp())) {
// Abort here
return FALSE;
} // END - if
}
// Get id from last INSERT command and secure id
-function SQL_INSERT_ID () {
- if (!SQL_IS_LINK_UP()) return FALSE;
+function getSqlInsertId () {
+ if (!isSqlLinkUp()) return FALSE;
return bigintval(mysql_insert_id());
}
// Escape a string for the database
-function SQL_ESCAPE ($str, $secureString = TRUE, $strip = TRUE) {
+function sqlEscapeString ($str, $secureString = TRUE, $strip = TRUE) {
// Is there cache?
if (!isset($GLOBALS['sql_escapes']['' . $str . ''])) {
// Debug message
//* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'str=' . $str . ' - BEFORE!');
// Prepare the string here
- $str = SQL_PREPARE_SQL_STRING($str);
+ $str = sqlPrepareQueryString($str);
// Debug message
//* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'str=' . $str . ' - AFTER!');
// Init (invalid) value
$ret = '!INVALID!';
- if (!SQL_IS_LINK_UP()) {
+ if (!isSqlLinkUp()) {
// Fall-back to escapeQuotes() when there is no link
$ret = escapeQuotes($str);
} elseif (function_exists('mysql_real_escape_string')) {
//* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'str=' . $str);
// The new and improved version
- $ret = mysql_real_escape_string($str, SQL_GET_LINK());
+ $ret = mysql_real_escape_string($str, getSqlLink());
// Debug message
//* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'str=' . $str . ',ret=' . $ret);
} elseif (function_exists('mysql_escape_string')) {
// The obsolete function
- $ret = mysql_escape_string($str, SQL_GET_LINK());
+ $ret = mysql_escape_string($str, getSqlLink());
} else {
// If nothing else works, fall back to escapeQuotes() again
$ret = escapeQuotes($str);
}
// Log SQL errors to debug.log in installation phase or call reportBug()
-function SQL_ERROR ($file, $line, $message) {
+function sqlError ($file, $line, $message) {
// Remember plain error in last_sql_error
$GLOBALS['last_sql_error'] = mysql_error();