X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=inc%2Fdb%2Flib-mysql3.php;h=95e409042d6c2421e031971dac3c5fa504521d0a;hb=d54624f97b6fbcfc0b9879166af5e6169a5af845;hp=f9f1e74d0241bb86b4d544b89edab0247797ca9d;hpb=eebdd0a1c8a8be46f7fb3dfd6721baeae645159f;p=mailer.git
diff --git a/inc/db/lib-mysql3.php b/inc/db/lib-mysql3.php
index f9f1e74d02..95e409042d 100644
--- a/inc/db/lib-mysql3.php
+++ b/inc/db/lib-mysql3.php
@@ -44,30 +44,39 @@ function SQL_QUERY($sql_string, $F, $L) {
// Remove \t, \n and \r from queries they may confuse some MySQL version I have heard
$sql_string = str_replace("\t", " ", str_replace("\n", " ", str_replace("\r", " ", $sql_string)));
+ // Starting time
+ $querytimeBefore = array_sum(explode(' ', microtime()));
+
// Run SQL command
$result = @mysql_query($sql_string, $link)
or ADD_FATAL($F." (".$L."):".mysql_error()."
".MYSQL_QUERY_STRING."
".$sql_string);
- // Count this query
- if (!isset($_CONFIG['sql_count'])) $_CONFIG['sql_count'] = 0;
- $_CONFIG['sql_count']++;
+ // Starting time
+ $querytimeAfter = array_sum(explode(' ', microtime()));
+
+ // Calculate query time
+ $queryTime = $querytimeAfter - $querytimeBefore;
- // Debug output
- //* DEBUG: */ print "Query=
".$sql_string."
, affected=".SQL_AFFECTEDROWS().", numrows=".SQL_NUMROWS($result)."
\n";
+ // Count this query
+ if (!isset($_CONFIG['sql_count'])) $_CONFIG['sql_count'] = 0;
+ $_CONFIG['sql_count']++;
+
+ // Debug output
+ //* DEBUG: */ print "Query=".$sql_string."
, affected=".SQL_AFFECTEDROWS().", numrows=".SQL_NUMROWS($result)."
\n";
if (($CSS != "1") && ($CSS != "-1") && (isBooleanConstantAndTrue('DEBUG_MODE')) && (DEBUG_SQL)) {
//
// Debugging stuff...
//
- $fp = @fopen(PATH."debug.log", 'a') or mxchange_die("Cannot write debug.log!");
+ $fp = @fopen(PATH."inc/cache/debug.log", 'a') or mxchange_die("Cannot write debug.log!");
if (!isset($OK)) {
// Write first entry
fwrite($fp, "Module=".$GLOBALS['module']."\n");
$OK = true;
}
- fwrite($fp, $F."(LINE=".$L."|NUM=".SQL_NUMROWS($result)."|AFFECTED=".SQL_AFFECTEDROWS()."): ".str_replace('\r', "", str_replace('\n', " ", $sql_string))."\n");
+ fwrite($fp, $F."(LINE=".$L."|NUM=".SQL_NUMROWS($result)."|AFFECTED=".SQL_AFFECTEDROWS()."|QUERYTIME:".$queryTime."): ".str_replace('\r', "", str_replace('\n', " ", $sql_string))."\n");
fclose($fp);
}
@@ -84,10 +93,13 @@ function SQL_QUERY($sql_string, $F, $L) {
// SQL num rows
function SQL_NUMROWS($result) {
- if ($result != false) {
+ // Is the result a valid resource?
+ if (is_resource($result)) {
+ // Get the count of rows from database
$lines = @mysql_num_rows($result);
- if (empty($lines)) $lines = "0";
+ // Is the result empty? Then we have an error!
+ if (empty($lines)) $lines = "0";
} else {
// No resource given, no lines found!
$lines = "0";
@@ -224,10 +236,11 @@ function SQL_INSERTID() {
// Escape a string for the database
function SQL_ESCAPE($str) {
global $link;
+
if (!is_resource($link)) {
// Fall-back to addslashes() when there is no link
return addslashes($str);
- }
+ } // END - if
if (function_exists('mysql_real_escape_string')) {
// The new and improved version
@@ -248,5 +261,30 @@ function SQL_RESULT_FROM_ARRAY ($table, $columns, $idRow, $id) {
// Return the result
return SQL_QUERY_ESC($SQL, array(bigintval($id)), __FILE__, __LINE__);
}
+// ALTER TABLE wrapper function
+function SQL_ALTER_TABLE($sql, $F, $L) {
+ // Shall we add?
+ if (eregi("ADD", $sql) > 0) {
+ // Extract table name
+ $tableArray = explode(" ", $sql);
+ $tableName = str_replace("`", "", $tableArray[2]);
+
+ // And column name as well
+ $columnName = str_replace("`", "", $tableArray[4]);
+
+ // Get column information
+ $result = SQL_QUERY_ESC("SHOW COLUMNS FROM %s LIKE '%s'",
+ array($tableName, $columnName), __FILE__, __LINE__);
+
+ // Do we have no entry?
+ if (SQL_NUMROWS($result) == 0) {
+ // Do the query
+ return SQL_QUERY($sql, $F, $L, false);
+ } // END - if
+ } else {
+ // Send it to the SQL_QUERY() function
+ return SQL_QUERY($sql, $F, $L, false);
+ }
+}
//
?>