Fixed a lot typos, thanks to profi-concept
[mailer.git] / inc / db / lib-mysql3.php
index 90db1da0b7c895dbf5487ff908f58ba9e5e19394..8d0ee5f467477c1b0700e9800f285203f611c026 100644 (file)
@@ -39,7 +39,7 @@ if (!defined('__SECURITY')) {
 
 // SQL queries
 function SQL_QUERY ($sql_string, $F, $L) {
-       global $link, $CSS, $_CONFIG, $OK;
+       global $link, $CSS, $OK;
 
        // Link is up?
        if (!is_resource($link)) return false;
@@ -67,7 +67,7 @@ Query string:<br />
        $queryTime = $querytimeAfter - $querytimeBefore;
 
        // Save last successfull query
-       $_CONFIG['db_last_query'] = $sql_string;
+       setConfigEntry('db_last_query', $sql_string);
 
        // Count this query
        incrementConfigEntry('sql_count');
@@ -90,12 +90,12 @@ Query string:<br />
        } // END - if
 
        // Count DB hits
-       if (getConfig('db_hits_run') == null) {
+       if (!isConfigEntrySet('db_hits_run')) {
                // Count in dummy variable
-               $_CONFIG['db_hits_run'] = 1;
+               setConfigEntry('db_hits_run', 1);
        } else {
                // Count to config array
-               $_CONFIG['db_hits_run']++;
+               incrementConfigEntry('db_hits_run');
        }
 
        // Return the result
@@ -103,7 +103,7 @@ Query string:<br />
 }
 
 // SQL num rows
-function SQL_NUMROWS($result) {
+function SQL_NUMROWS ($result) {
        // Is the result a valid resource?
        if (is_resource($result)) {
                // Get the count of rows from database
@@ -176,28 +176,26 @@ function SQL_FETCHARRAY($res, $nr=0, $remove_numerical=true) {
 }
 
 // SQL result
-function SQL_RESULT($res, $row, $field) {
+function SQL_RESULT ($res, $row, $field) {
        $result = mysql_result($res, $row, $field);
        return $result;
 }
 // SQL connect
-function SQL_CONNECT($host, $login, $password, $F, $L) {
+function SQL_CONNECT ($host, $login, $password, $F, $L) {
        $connect = mysql_connect($host, $login, $password) or addFatalMessage($F." (".$L."):".mysql_error());
        return $connect;
 }
 // SQL select database
-function SQL_SELECT_DB($dbName, $link, $F, $L) {
-       $select = false;
-       if (is_resource($link)) {
-               $select = mysql_select_db($dbName, $link) or addFatalMessage($F." (".$L."):".mysql_error());
-       }
-       return $select;
+function SQL_SELECT_DB ($dbName, $link, $F, $L) {
+       // Is there still a valid link? If not, skip it.
+       if (!is_resource($link)) return false;
+
+       return mysql_select_db($dbName, $link) or addFatalMessage($F." (".$L."):".mysql_error());
 }
 // SQL close link
-function SQL_CLOSE(&$link, $F, $L) {
-       global $_CONFIG, $cacheInstance, $cacheArray;
+function SQL_CLOSE (&$link, $F, $L) {
+       global $cacheInstance, $cacheArray;
 
-       // Is there still a valid link?
        if (!is_resource($link)) {
                // Skip double close
                return false;
@@ -207,7 +205,7 @@ function SQL_CLOSE(&$link, $F, $L) {
        //* DEBUG: */ echo "DB=".getConfig('db_hits').",CACHE=".getConfig('cache_hits')."<br />\n";
        if ((GET_EXT_VERSION("cache") >= "0.0.7") && (getConfig('db_hits') > 0) && (getConfig('cache_hits') > 0) && (is_object($cacheInstance))) {
                // Add new hits
-               $_CONFIG['db_hits'] += getConfig('db_hits_run');
+               incrementConfigEntry('db_hits', getConfig('db_hits_run'));
 
                // Update counter for db/cache
                UPDATE_CONFIG(array("db_hits", "cache_hits"), array(bigintval(getConfig('db_hits')), bigintval(getConfig('cache_hits'))));
@@ -268,9 +266,13 @@ function SQL_QUERY_ESC ($qstring, $data, $file, $line, $run=true, $strip=true) {
        // Was the eval() command fine?
        if ($query == "failed") {
                // Something went wrong?
-               print "eval=".htmlentities($eval)."<pre>";
-               debug_print_backtrace();
-               die("</pre>");
+               printf("eval=%s\n<pre>%s</pre>",
+                       htmlentities($eval),
+                       debug_get_printable_backtrace()
+               );
+
+               // Abort further code executions
+               exit;
        } // END - if
 
        if ($run) {
@@ -320,10 +322,10 @@ function SQL_ESCAPE ($str, $secureString=true,$strip=true) {
 // SELECT query string from table, columns and so on... ;-)
 function SQL_RESULT_FROM_ARRAY ($table, $columns, $idRow, $id, $F, $L) {
        // Is columns an array?
-       if (!is_array($columns) {
+       if (!is_array($columns)) {
                // No array
                trigger_error(sprintf("columns is not array. %s!=array", gettype($columns)));
-       }
+       } // END  - if
 
        // Prepare the SQL statement
        $SQL = "SELECT `".implode("`, `", $columns)."` FROM `{!_MYSQL_PREFIX!}_%s` WHERE ``='%s' LIMIT 1";
@@ -359,6 +361,7 @@ function SQL_ALTER_TABLE ($sql, $F, $L) {
                        array($tableName, $columnName), $F, $L);
 
                // Do we have no entry on ADD or an entry on DROP?
+               // 123           4       4     3    3     4           4    32    23           4       4     3    3     4            4    321
                if (((SQL_NUMROWS($result) == 0) && (eregi("ADD", $sql) > 0)) || ((SQL_NUMROWS($result) == 1) && (eregi("DROP", $sql) > 0))) {
                        // Do the query
                        $result = SQL_QUERY($sql, $F, $L, false);