1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-01 04:10:38 +02:00

Get rid of some direct calls to mysql handler

This commit is contained in:
e107steved
2009-05-24 15:34:37 +00:00
parent 5552265396
commit f6dc16a61b
3 changed files with 349 additions and 228 deletions

View File

@@ -11,9 +11,9 @@
| GNU General Public License (http://gnu.org). | GNU General Public License (http://gnu.org).
| |
| $Source: /cvs_backup/e107_0.8/e107_admin/update_routines.php,v $ | $Source: /cvs_backup/e107_0.8/e107_admin/update_routines.php,v $
| $Revision: 1.36 $ | $Revision: 1.37 $
| $Date: 2008-12-30 15:56:12 $ | $Date: 2009-05-24 15:34:36 $
| $Author: secretr $ | $Author: e107steved $
+----------------------------------------------------------------------------+ +----------------------------------------------------------------------------+
*/ */
@@ -492,7 +492,7 @@ function update_706_to_800($type='')
} }
if (mysql_table_exists('newsfeed')) if ($sql->db_Table_exists('newsfeed'))
{ // Need to extend field newsfeed_url varchar(250) NOT NULL default '' { // Need to extend field newsfeed_url varchar(250) NOT NULL default ''
if ($sql -> db_Query("SHOW FIELDS FROM ".MPREFIX."newsfeed LIKE 'newsfeed_url'")) if ($sql -> db_Query("SHOW FIELDS FROM ".MPREFIX."newsfeed LIKE 'newsfeed_url'"))
{ {
@@ -500,7 +500,7 @@ function update_706_to_800($type='')
if (str_replace('varchar', 'char', strtolower($row['Type'])) != 'char(250)') if (str_replace('varchar', 'char', strtolower($row['Type'])) != 'char(250)')
{ {
if ($just_check) return update_needed('Update newsfeed field definition'); if ($just_check) return update_needed('Update newsfeed field definition');
mysql_query("ALTER TABLE `".MPREFIX."newsfeed` MODIFY `newsfeed_url` VARCHAR(250) NOT NULL DEFAULT '' "); $sql->db_Select_gen("ALTER TABLE `".MPREFIX."newsfeed` MODIFY `newsfeed_url` VARCHAR(250) NOT NULL DEFAULT '' ");
$updateMessages[] = LAN_UPDATE_40; $updateMessages[] = LAN_UPDATE_40;
catch_error(); catch_error();
} }
@@ -508,7 +508,7 @@ function update_706_to_800($type='')
} }
if (mysql_table_exists('download')) if ($sql->db_Table_exists('download'))
{ // Need to extend field download_url varchar(255) NOT NULL default '' { // Need to extend field download_url varchar(255) NOT NULL default ''
if ($sql -> db_Query("SHOW FIELDS FROM ".MPREFIX."download LIKE 'download_url'")) if ($sql -> db_Query("SHOW FIELDS FROM ".MPREFIX."download LIKE 'download_url'"))
{ {
@@ -516,22 +516,22 @@ function update_706_to_800($type='')
if (str_replace('varchar', 'char', strtolower($row['Type'])) != 'char(255)') if (str_replace('varchar', 'char', strtolower($row['Type'])) != 'char(255)')
{ {
if ($just_check) return update_needed('Update download table field definition'); if ($just_check) return update_needed('Update download table field definition');
mysql_query("ALTER TABLE `".MPREFIX."download` MODIFY `download_url` VARCHAR(255) NOT NULL DEFAULT '' "); $sql->db_Select_gen("ALTER TABLE `".MPREFIX."download` MODIFY `download_url` VARCHAR(255) NOT NULL DEFAULT '' ");
$updateMessages[] = LAN_UPDATE_52; $updateMessages[] = LAN_UPDATE_52;
catch_error(); catch_error();
} }
} }
} }
if (mysql_table_exists('download_mirror')) if ($sql->db_Table_exists('download_mirror'))
{ // Need to extend field download_url varchar(255) NOT NULL default '' { // Need to extend field download_url varchar(255) NOT NULL default ''
if ($sql -> db_Query("SHOW FIELDS FROM ".MPREFIX."download_mirror LIKE 'mirror_url'")) if ($sql->db_Select_gen("SHOW FIELDS FROM ".MPREFIX."download_mirror LIKE 'mirror_url'"))
{ {
$row = $sql -> db_Fetch(); $row = $sql -> db_Fetch();
if (str_replace('varchar', 'char', strtolower($row['Type'])) != 'char(255)') if (str_replace('varchar', 'char', strtolower($row['Type'])) != 'char(255)')
{ {
if ($just_check) return update_needed('Update download mirror table field definition'); if ($just_check) return update_needed('Update download mirror table field definition');
mysql_query("ALTER TABLE `".MPREFIX."download_mirror` MODIFY `mirror_url` VARCHAR(255) NOT NULL DEFAULT '' "); $sql->db_Select_gen("ALTER TABLE `".MPREFIX."download_mirror` MODIFY `mirror_url` VARCHAR(255) NOT NULL DEFAULT '' ");
$updateMessages[] = LAN_UPDATE_53; $updateMessages[] = LAN_UPDATE_53;
catch_error(); catch_error();
} }
@@ -557,7 +557,7 @@ function update_706_to_800($type='')
// Tables defined in core_sql.php // Tables defined in core_sql.php
//--------------------------------- //---------------------------------
if (mysql_table_exists('dblog') && !mysql_table_exists('admin_log')) if ($sql->db_Table_exists('dblog') && !$sql->db_Table_exists('admin_log'))
{ {
if ($just_check) return update_needed('Rename dblog to admin_log'); if ($just_check) return update_needed('Rename dblog to admin_log');
$sql->db_Select_gen('ALTER TABLE `'.MPREFIX.'dblog` RENAME `'.MPREFIX.'admin_log`'); $sql->db_Select_gen('ALTER TABLE `'.MPREFIX.'dblog` RENAME `'.MPREFIX.'admin_log`');
@@ -566,7 +566,7 @@ function update_706_to_800($type='')
} }
// Next bit will be needed only by the brave souls who used an early CVS - probably delete before release // Next bit will be needed only by the brave souls who used an early CVS - probably delete before release
if (mysql_table_exists('rl_history') && !mysql_table_exists('dblog')) if ($sql->db_Table_exists('rl_history') && !$sql->db_Table_exists('dblog'))
{ {
if ($just_check) return update_needed('Rename rl_history to dblog'); if ($just_check) return update_needed('Rename rl_history to dblog');
$sql->db_Select_gen('ALTER TABLE `'.MPREFIX.'rl_history` RENAME `'.MPREFIX.'dblog`'); $sql->db_Select_gen('ALTER TABLE `'.MPREFIX.'rl_history` RENAME `'.MPREFIX.'dblog`');
@@ -578,7 +578,7 @@ function update_706_to_800($type='')
// New tables required (list at top. Definitions in core_sql.php) // New tables required (list at top. Definitions in core_sql.php)
foreach ($new_tables as $nt) foreach ($new_tables as $nt)
{ {
if (!mysql_table_exists($nt)) if (!$sql->db_Table_exists($nt))
{ {
if ($just_check) return update_needed("Add table: ".$nt); if ($just_check) return update_needed("Add table: ".$nt);
// Get the definition // Get the definition
@@ -623,7 +623,7 @@ function update_706_to_800($type='')
if (E107_DBG_FILLIN8) echo "List of changes found:<br />".$db_parser->make_changes_list($diffs); if (E107_DBG_FILLIN8) echo "List of changes found:<br />".$db_parser->make_changes_list($diffs);
$qry = 'ALTER TABLE '.MPREFIX.$ct.' '.implode(', ',$diffs[1]); $qry = 'ALTER TABLE '.MPREFIX.$ct.' '.implode(', ',$diffs[1]);
if (E107_DBG_FILLIN8) echo "Update Query used: ".$qry."<br />"; if (E107_DBG_FILLIN8) echo "Update Query used: ".$qry."<br />";
mysql_query($qry); $sql->db_Select_gen($qry);
$updateMessages[] = LAN_UPDATE_47.$ct; $updateMessages[] = LAN_UPDATE_47.$ct;
catch_error(); catch_error();
} }
@@ -668,7 +668,7 @@ function update_706_to_800($type='')
// Do the changes here // Do the changes here
$qry = 'ALTER TABLE '.MPREFIX.$ct.' '.implode(', ',$diffs[1]); $qry = 'ALTER TABLE '.MPREFIX.$ct.' '.implode(', ',$diffs[1]);
if (E107_DBG_FILLIN8) echo "Update Query used: ".$qry."<br />"; if (E107_DBG_FILLIN8) echo "Update Query used: ".$qry."<br />";
mysql_query($qry); $sql->db_Select_gen($qry);
$updateMessages[] = LAN_UPDATE_51.$ct; $updateMessages[] = LAN_UPDATE_51.$ct;
catch_error(); catch_error();
} }
@@ -680,10 +680,10 @@ function update_706_to_800($type='')
// Obsolete tables (list at top) // Obsolete tables (list at top)
foreach ($obs_tables as $ot) foreach ($obs_tables as $ot)
{ {
if (mysql_table_exists($ot)) if ($sql->db_Table_exists($ot))
{ {
if ($just_check) return update_needed("Delete table: ".$ot); if ($just_check) return update_needed("Delete table: ".$ot);
mysql_query('DROP TABLE `'.MPREFIX.$ot.'`'); $sql->db_Select_gen('DROP TABLE `'.MPREFIX.$ot.'`');
$updateMessages[] = LAN_UPDATE_48.$ot; $updateMessages[] = LAN_UPDATE_48.$ot;
} }
} }
@@ -693,14 +693,14 @@ function update_706_to_800($type='')
// Set to varchar(45) - just in case something uses the IPV4 subnet (see http://en.wikipedia.org/wiki/IPV6#Notation) // Set to varchar(45) - just in case something uses the IPV4 subnet (see http://en.wikipedia.org/wiki/IPV6#Notation)
foreach ($ip_upgrade as $t => $f) foreach ($ip_upgrade as $t => $f)
{ {
if (mysql_table_exists($t)) if ($sql->db_Table_exists($t))
{ // Check for table - might add some core plugin tables in here { // Check for table - might add some core plugin tables in here
if ($field_info = ($sql->db_Field($t, $f, '', TRUE))) if ($field_info = ($sql->db_Field($t, $f, '', TRUE)))
{ {
if (strtolower($field_info['Type']) != 'varchar(45)') if (strtolower($field_info['Type']) != 'varchar(45)')
{ {
if ($just_check) return update_needed('Update IP address field '.$f.' in table '.$t); if ($just_check) return update_needed('Update IP address field '.$f.' in table '.$t);
mysql_query("ALTER TABLE `".MPREFIX.$t."` MODIFY `{$f}` VARCHAR(45) NOT NULL DEFAULT '';"); $sql->db_Select_gen("ALTER TABLE `".MPREFIX.$t."` MODIFY `{$f}` VARCHAR(45) NOT NULL DEFAULT '';");
$updateMessages[] = LAN_UPDATE_49.$t.' - '.$f; $updateMessages[] = LAN_UPDATE_49.$t.' - '.$f;
catch_error(); catch_error();
} }
@@ -748,7 +748,7 @@ function update_70x_to_706($type='')
if(!$sql->db_Field("plugin",5)) // not plugin_rss so just add the new one. if(!$sql->db_Field("plugin",5)) // not plugin_rss so just add the new one.
{ {
if ($just_check) return update_needed(); if ($just_check) return update_needed();
mysql_query("ALTER TABLE `".MPREFIX."plugin` ADD `plugin_addons` TEXT NOT NULL ;"); $sql->db_Select_gen("ALTER TABLE `".MPREFIX."plugin` ADD `plugin_addons` TEXT NOT NULL ;");
catch_error(); catch_error();
} }
@@ -756,7 +756,7 @@ function update_70x_to_706($type='')
if($sql->db_Field("plugin",5) == "plugin_rss") if($sql->db_Field("plugin",5) == "plugin_rss")
{ {
if ($just_check) return update_needed(); if ($just_check) return update_needed();
mysql_query("ALTER TABLE `".MPREFIX."plugin` CHANGE `plugin_rss` `plugin_addons` TEXT NOT NULL;"); $sql->db_Select_gen("ALTER TABLE `".MPREFIX."plugin` CHANGE `plugin_rss` `plugin_addons` TEXT NOT NULL;");
catch_error(); catch_error();
} }
@@ -764,16 +764,16 @@ function update_70x_to_706($type='')
if($sql->db_Field("dblog",5) == "dblog_query") if($sql->db_Field("dblog",5) == "dblog_query")
{ {
if ($just_check) return update_needed(); if ($just_check) return update_needed();
mysql_query("ALTER TABLE `".MPREFIX."dblog` CHANGE `dblog_query` `dblog_title` VARCHAR( 255 ) NOT NULL DEFAULT '';"); $sql->db_Select_gen("ALTER TABLE `".MPREFIX."dblog` CHANGE `dblog_query` `dblog_title` VARCHAR( 255 ) NOT NULL DEFAULT '';");
catch_error(); catch_error($sql);
mysql_query("ALTER TABLE `".MPREFIX."dblog` CHANGE `dblog_remarks` `dblog_remarks` TEXT NOT NULL;"); $sql->db_Select_gen("ALTER TABLE `".MPREFIX."dblog` CHANGE `dblog_remarks` `dblog_remarks` TEXT NOT NULL;");
catch_error(); catch_error($sql);
} }
if(!$sql->db_Field("plugin","plugin_path","UNIQUE")) if(!$sql->db_Field("plugin","plugin_path","UNIQUE"))
{ {
if ($just_check) return update_needed(); if ($just_check) return update_needed();
if(!mysql_query("ALTER TABLE `".MPREFIX."plugin` ADD UNIQUE (`plugin_path`);")) if(!$sql->db_Select_gen("ALTER TABLE `".MPREFIX."plugin` ADD UNIQUE (`plugin_path`);"))
{ {
$mes = LAN_UPDATE_12." : <a href='".e_ADMIN."db.php?plugin'>".ADLAN_145."</a>."; $mes = LAN_UPDATE_12." : <a href='".e_ADMIN."db.php?plugin'>".ADLAN_145."</a>.";
//$ns -> tablerender(LAN_ERROR,$mes); //$ns -> tablerender(LAN_ERROR,$mes);
@@ -785,7 +785,7 @@ function update_70x_to_706($type='')
if(!$sql->db_Field("online",6)) // online_active field if(!$sql->db_Field("online",6)) // online_active field
{ {
if ($just_check) return update_needed(); if ($just_check) return update_needed();
mysql_query("ALTER TABLE ".MPREFIX."online ADD online_active INT(10) UNSIGNED NOT NULL DEFAULT '0'"); $sql->db_Select_gen("ALTER TABLE ".MPREFIX."online ADD online_active INT(10) UNSIGNED NOT NULL DEFAULT '0'");
catch_error(); catch_error();
} }
@@ -795,9 +795,9 @@ function update_70x_to_706($type='')
if (!in_array('tmp_ip', $row)) if (!in_array('tmp_ip', $row))
{ {
if ($just_check) return update_needed(); if ($just_check) return update_needed();
mysql_query("ALTER TABLE `".MPREFIX."tmp` ADD INDEX `tmp_ip` (`tmp_ip`);"); $sql->db_Select_gen("ALTER TABLE `".MPREFIX."tmp` ADD INDEX `tmp_ip` (`tmp_ip`);");
mysql_query("ALTER TABLE `".MPREFIX."upload` ADD INDEX `upload_active` (`upload_active`);"); $sql->db_Select_gen("ALTER TABLE `".MPREFIX."upload` ADD INDEX `upload_active` (`upload_active`);");
mysql_query("ALTER TABLE `".MPREFIX."generic` ADD INDEX `gen_type` (`gen_type`);"); $sql->db_Select_gen("ALTER TABLE `".MPREFIX."generic` ADD INDEX `gen_type` (`gen_type`);");
} }
} }
@@ -869,19 +869,21 @@ function update_needed($message='')
} }
/*
function mysql_table_exists($table) function mysql_table_exists($table)
{ {
$exists = mysql_query("SELECT 1 FROM ".MPREFIX."$table LIMIT 0"); $exists = mysql_query("SELECT 1 FROM ".MPREFIX."$table LIMIT 0");
if ($exists) return TRUE; if ($exists) return TRUE;
return FALSE; return FALSE;
} }
*/
// Add index to a table. Returns FALSE if not required. Returns a message if required and just checking // Add index to a table. Returns FALSE if not required. Returns a message if required and just checking
function addIndexToTable($target, $indexSpec, $just_check, &$updateMessages, $optionalTable=FALSE) function addIndexToTable($target, $indexSpec, $just_check, &$updateMessages, $optionalTable=FALSE)
{ {
global $sql; global $sql;
if (!mysql_table_exists($target)) if (!$sql->db_Table_exists($target))
{ {
if ($optionalTable) if ($optionalTable)
{ {
@@ -890,7 +892,7 @@ function addIndexToTable($target, $indexSpec, $just_check, &$updateMessages, $op
$updateMessages[] = str_replace(array('--TABLE--','--INDEX--'),array($target,$indexSpec),LAN_UPDATE_54); $updateMessages[] = str_replace(array('--TABLE--','--INDEX--'),array($target,$indexSpec),LAN_UPDATE_54);
return !$just_check; // No point carrying on - return 'nothing to do' return !$just_check; // No point carrying on - return 'nothing to do'
} }
if ($sql -> db_Query("SHOW INDEX FROM ".MPREFIX.$target)) if ($sql->db_Select_gen("SHOW INDEX FROM ".MPREFIX.$target))
{ {
$found = FALSE; $found = FALSE;
while ($row = $sql -> db_Fetch()) while ($row = $sql -> db_Fetch())
@@ -905,22 +907,22 @@ function addIndexToTable($target, $indexSpec, $just_check, &$updateMessages, $op
{ {
return 'Required to add index to '.$target; return 'Required to add index to '.$target;
} }
mysql_query("ALTER TABLE `".MPREFIX.$target."` ADD INDEX `".$indexSpec."` (`".$indexSpec."`);"); $sql->db_Select_gen("ALTER TABLE `".MPREFIX.$target."` ADD INDEX `".$indexSpec."` (`".$indexSpec."`);");
$updateMessages[] = str_replace(array('--TABLE--','--INDEX--'),array($target,$indexSpec),LAN_UPDATE_37); $updateMessages[] = str_replace(array('--TABLE--','--INDEX--'),array($target,$indexSpec),LAN_UPDATE_37);
} }
return FALSE; return FALSE;
} }
function catch_error() function catch_error(&$target)
{ {
if (mysql_error()!='' && E107_DEBUG_LEVEL != 0) if ($target->getLastErrorText() != '' && E107_DEBUG_LEVEL != 0)
{ {
$tmp2 = debug_backtrace(); $tmp2 = debug_backtrace();
$tmp = mysql_error(); $tmp = $target->getLastErrorText();
echo $tmp." [ ".basename(__FILE__)." on line ".$tmp2[0]['line']."] <br />"; echo $tmp." [ ".basename(__FILE__)." on line ".$tmp2[0]['line']."] <br />";
} }
return; return;
} }

View File

@@ -9,9 +9,9 @@
* mySQL Handler * mySQL Handler
* *
* $Source: /cvs_backup/e107_0.8/e107_handlers/mysql_class.php,v $ * $Source: /cvs_backup/e107_0.8/e107_handlers/mysql_class.php,v $
* $Revision: 1.37 $ * $Revision: 1.38 $
* $Date: 2009-01-18 17:05:08 $ * $Date: 2009-05-24 15:34:37 $
* $Author: mcfly_e107 $ * $Author: e107steved $
*/ */
if(defined('MYSQL_LIGHT')) if(defined('MYSQL_LIGHT'))
@@ -44,8 +44,8 @@ $db_ConnectionID = NULL; // Stores ID for the first DB connection used - which s
* MySQL Abstraction class * MySQL Abstraction class
* *
* @package e107 * @package e107
* @version $Revision: 1.37 $ * @version $Revision: 1.38 $
* @author $Author: mcfly_e107 $ * @author $Author: e107steved $
*/ */
class db { class db {
@@ -57,7 +57,9 @@ class db {
var $mySQLaccess; var $mySQLaccess;
var $mySQLresult; var $mySQLresult;
var $mySQLrows; var $mySQLrows;
var $mySQLerror; var $mySQLerror; // Error reporting mode - TRUE shows messages
var $mySQLlastErrNum; // Number of last error
var $mySQLlastErrText; // Text of last error (empty string if no error)
var $mySQLcurTable; var $mySQLcurTable;
var $mySQLlanguage; var $mySQLlanguage;
var $mySQLinfo; var $mySQLinfo;
@@ -72,20 +74,20 @@ class db {
*/ */
function db() function db()
{ {
global $pref, $eTraffic, $db_defaultPrefix; global $pref, $eTraffic, $db_defaultPrefix;
$eTraffic->BumpWho('Create db object', 1); $eTraffic->BumpWho('Create db object', 1);
$this->mySQLPrefix = MPREFIX; // Set the default prefix - may be overridden $this->mySQLPrefix = MPREFIX; // Set the default prefix - may be overridden
$langid = 'e107language_'.$pref['cookie_name']; $langid = 'e107language_'.$pref['cookie_name'];
if ($pref['user_tracking'] == 'session') if ($pref['user_tracking'] == 'session')
{ {
if (!isset($_SESSION[$langid])) { return; } if (!isset($_SESSION[$langid])) { return; }
$this->mySQLlanguage = $_SESSION[$langid]; $this->mySQLlanguage = $_SESSION[$langid];
} }
else else
{ {
if (!isset($_COOKIE[$langid])) { return; } if (!isset($_COOKIE[$langid])) { return; }
$this->mySQLlanguage = $_COOKIE[$langid]; $this->mySQLlanguage = $_COOKIE[$langid];
} }
} }
/** /**
@@ -154,28 +156,32 @@ class db {
*/ */
function db_Mark_Time($sMarker) function db_Mark_Time($sMarker)
{ {
if (E107_DEBUG_LEVEL > 0) if (E107_DEBUG_LEVEL > 0)
{ {
global $db_debug; global $db_debug;
$db_debug->Mark_Time($sMarker); $db_debug->Mark_Time($sMarker);
} }
} }
/** /**
* @return void * @return void
* @desc Enter description here... * @desc Enter description here...
* @access private * @access private
*/ */
function db_Show_Performance() { function db_Show_Performance()
{
return $db_debug->Show_Performance(); return $db_debug->Show_Performance();
} }
/** /**
* @return void * @return void
* @desc add query to dblog table * @desc add query to dblog table
* @access private * @access private
*/ */
function db_Write_log($log_type = '', $log_remark = '', $log_query = '') { function db_Write_log($log_type = '', $log_remark = '', $log_query = '')
{
global $tp, $e107; global $tp, $e107;
list($time_usec, $time_sec) = explode(" ", microtime()); list($time_usec, $time_sec) = explode(" ", microtime());
$uid = (USER) ? USERID : '0'; $uid = (USER) ? USERID : '0';
@@ -185,6 +191,7 @@ class db {
$this->db_Insert('dblog', "0, {$time_sec}, {$time_usec}, '{$log_type}', 'DBDEBUG', {$uid}, '{$userstring}', '{$ip}', '', '{$log_remark}', '{$qry}'"); $this->db_Insert('dblog', "0, {$time_sec}, {$time_usec}, '{$log_type}', 'DBDEBUG', {$uid}, '{$userstring}', '{$ip}', '', '{$log_remark}', '{$qry}'");
} }
/** /**
* @return unknown * @return unknown
* @param unknown $query * @param unknown $query
@@ -193,18 +200,21 @@ class db {
* @access private * @access private
* This is the 'core' routine which handles much of the interface between other functions and the DB * This is the 'core' routine which handles much of the interface between other functions and the DB
*/ */
function db_Query($query, $rli = NULL, $qry_from = '', $debug = FALSE, $log_type = '', $log_remark = '') { function db_Query($query, $rli = NULL, $qry_from = '', $debug = FALSE, $log_type = '', $log_remark = '')
{
global $db_time,$db_mySQLQueryCount,$queryinfo, $eTraffic; global $db_time,$db_mySQLQueryCount,$queryinfo, $eTraffic;
$db_mySQLQueryCount++; $db_mySQLQueryCount++;
if ($debug == 'now') { if ($debug == 'now')
{
echo "** $query<br />\n"; echo "** $query<br />\n";
} }
if ($debug !== FALSE || strstr(e_QUERY, 'showsql')) if ($debug !== FALSE || strstr(e_QUERY, 'showsql'))
{ {
$queryinfo[] = "<b>{$qry_from}</b>: $query"; $queryinfo[] = "<b>{$qry_from}</b>: $query";
} }
if ($log_type != '') { if ($log_type != '')
{
$this->db_Write_log($log_type, $log_remark, $query); $this->db_Write_log($log_type, $log_remark, $query);
} }
@@ -225,13 +235,14 @@ class db {
if ((strpos($query,'SQL_CALC_FOUND_ROWS') !== FALSE) && (strpos($query,'SELECT') !== FALSE)) if ((strpos($query,'SQL_CALC_FOUND_ROWS') !== FALSE) && (strpos($query,'SELECT') !== FALSE))
{ // Need to get the total record count as well. Return code is a resource identifier { // Need to get the total record count as well. Return code is a resource identifier
// Have to do this before any debug action, otherwise this bit gets messed up // Have to do this before any debug action, otherwise this bit gets messed up
$fr = mysql_query("SELECT FOUND_ROWS()", $this->mySQLaccess); $fr = mysql_query("SELECT FOUND_ROWS()", $this->mySQLaccess);
$rc = mysql_fetch_array($fr); $rc = mysql_fetch_array($fr);
$this->total_results = $rc['FOUND_ROWS()']; $this->total_results = $rc['FOUND_ROWS()'];
} }
if (E107_DEBUG_LEVEL) { if (E107_DEBUG_LEVEL)
{
global $db_debug; global $db_debug;
$aTrace = debug_backtrace(); $aTrace = debug_backtrace();
$pTable = $this->mySQLcurTable; $pTable = $this->mySQLcurTable;
@@ -240,16 +251,20 @@ class db {
} else { } else {
$this->mySQLcurTable = ''; // clear before next query $this->mySQLcurTable = ''; // clear before next query
} }
if(is_object($db_debug)) { if(is_object($db_debug))
{
$buglink = is_null($rli) ? $this->mySQLaccess : $rli; $buglink = is_null($rli) ? $this->mySQLaccess : $rli;
$nFields = $db_debug->Mark_Query($query, $buglink, $sQryRes, $aTrace, $mytime, $pTable); $nFields = $db_debug->Mark_Query($query, $buglink, $sQryRes, $aTrace, $mytime, $pTable);
} else { }
else
{
echo "what happened to db_debug??!!<br />"; echo "what happened to db_debug??!!<br />";
} }
} }
return $sQryRes; return $sQryRes;
} }
/** /**
* @return int Number of rows or false on error * @return int Number of rows or false on error
* *
@@ -275,38 +290,52 @@ class db {
*/ */
function db_Select($table, $fields = '*', $arg = '', $mode = 'default', $debug = FALSE, $log_type = '', $log_remark = '') function db_Select($table, $fields = '*', $arg = '', $mode = 'default', $debug = FALSE, $log_type = '', $log_remark = '')
{ {
global $db_mySQLQueryCount; global $db_mySQLQueryCount;
$table = $this->db_IsLang($table); $table = $this->db_IsLang($table);
$this->mySQLcurTable = $table; $this->mySQLcurTable = $table;
if ($arg != '' && $mode == 'default') if ($arg != '' && $mode == 'default')
{ {
if ($this->mySQLresult = $this->db_Query('SELECT '.$fields.' FROM '.$this->mySQLPrefix.$table.' WHERE '.$arg, NULL, 'db_Select', $debug, $log_type, $log_remark)) { if ($this->mySQLresult = $this->db_Query('SELECT '.$fields.' FROM '.$this->mySQLPrefix.$table.' WHERE '.$arg, NULL, 'db_Select', $debug, $log_type, $log_remark))
{
$this->dbError('dbQuery'); $this->dbError('dbQuery');
return $this->db_Rows(); return $this->db_Rows();
} else { }
else
{
$this->dbError("db_Select (SELECT $fields FROM ".$this->mySQLPrefix."{$table} WHERE {$arg})"); $this->dbError("db_Select (SELECT $fields FROM ".$this->mySQLPrefix."{$table} WHERE {$arg})");
return FALSE; return FALSE;
} }
} elseif ($arg != '' && $mode != 'default') { }
if ($this->mySQLresult = $this->db_Query('SELECT '.$fields.' FROM '.$this->mySQLPrefix.$table.' '.$arg, NULL, 'db_Select', $debug, $log_type, $log_remark)) { elseif ($arg != '' && $mode != 'default')
{
if ($this->mySQLresult = $this->db_Query('SELECT '.$fields.' FROM '.$this->mySQLPrefix.$table.' '.$arg, NULL, 'db_Select', $debug, $log_type, $log_remark))
{
$this->dbError('dbQuery'); $this->dbError('dbQuery');
return $this->db_Rows(); return $this->db_Rows();
} else { }
else
{
$this->dbError("db_Select (SELECT {$fields} FROM ".$this->mySQLPrefix."{$table} {$arg})"); $this->dbError("db_Select (SELECT {$fields} FROM ".$this->mySQLPrefix."{$table} {$arg})");
return FALSE; return FALSE;
} }
} else { }
if ($this->mySQLresult = $this->db_Query('SELECT '.$fields.' FROM '.$this->mySQLPrefix.$table, NULL, 'db_Select', $debug, $log_type, $log_remark)) { else
{
if ($this->mySQLresult = $this->db_Query('SELECT '.$fields.' FROM '.$this->mySQLPrefix.$table, NULL, 'db_Select', $debug, $log_type, $log_remark))
{
$this->dbError('dbQuery'); $this->dbError('dbQuery');
return $this->db_Rows(); return $this->db_Rows();
} else { }
else
{
$this->dbError("db_Select (SELECT {$fields} FROM ".$this->mySQLPrefix."{$table})"); $this->dbError("db_Select (SELECT {$fields} FROM ".$this->mySQLPrefix."{$table})");
return FALSE; return FALSE;
} }
} }
} }
/** /**
* @return int Last insert ID or false on error * @return int Last insert ID or false on error
* @param string $table * @param string $table
@@ -333,7 +362,7 @@ class db {
$arg = $_tmp; $arg = $_tmp;
unset($_tmp); unset($_tmp);
} }
if(!isset($arg['data'])) { return false; } if(!isset($arg['data'])) { return false; }
$fieldTypes = $this->_getTypes($arg); $fieldTypes = $this->_getTypes($arg);
$keyList= '`'.implode('`,`', array_keys($arg['data'])).'`'; $keyList= '`'.implode('`,`', array_keys($arg['data'])).'`';
@@ -354,21 +383,23 @@ class db {
if(!$this->mySQLaccess) if(!$this->mySQLaccess)
{ {
global $db_ConnectionID; global $db_ConnectionID;
$this->mySQLaccess = $db_ConnectionID; $this->mySQLaccess = $db_ConnectionID;
} }
if ($result = $this->mySQLresult = $this->db_Query($query, NULL, 'db_Insert', $debug, $log_type, $log_remark )) if ($result = $this->mySQLresult = $this->db_Query($query, NULL, 'db_Insert', $debug, $log_type, $log_remark ))
{ {
$tmp = mysql_insert_id($this->mySQLaccess); $tmp = mysql_insert_id($this->mySQLaccess);
$this->dbError('db_Insert');
return ($tmp) ? $tmp : TRUE; // return true even if table doesn't have auto-increment. return ($tmp) ? $tmp : TRUE; // return true even if table doesn't have auto-increment.
} }
else else
{ {
$this->dbError("db_Insert ($query)"); $this->dbError("db_Insert ({$query})");
return FALSE; return FALSE;
} }
} }
/** /**
* @return int number of affected rows, or false on error * @return int number of affected rows, or false on error
* @param string $table * @param string $table
@@ -395,13 +426,13 @@ class db {
if(!$this->mySQLaccess) if(!$this->mySQLaccess)
{ {
global $db_ConnectionID; global $db_ConnectionID;
$this->mySQLaccess = $db_ConnectionID; $this->mySQLaccess = $db_ConnectionID;
} }
if (is_array($arg)) // Remove the need for a separate db_UpdateArray() function. if (is_array($arg)) // Remove the need for a separate db_UpdateArray() function.
{ {
$new_data = ''; $new_data = '';
if(!isset($arg['_FIELD_TYPES']) && !isset($arg['data'])) if(!isset($arg['_FIELD_TYPES']) && !isset($arg['data']))
{ {
//Convert data if not using 'new' format (is this needed?) //Convert data if not using 'new' format (is this needed?)
$_tmp = array(); $_tmp = array();
@@ -428,12 +459,13 @@ class db {
if ($result = $this->mySQLresult = $this->db_Query('UPDATE '.$this->mySQLPrefix.$table.' SET '.$arg, NULL, 'db_Update', $debug, $log_type, $log_remark)) if ($result = $this->mySQLresult = $this->db_Query('UPDATE '.$this->mySQLPrefix.$table.' SET '.$arg, NULL, 'db_Update', $debug, $log_type, $log_remark))
{ {
$result = mysql_affected_rows($this->mySQLaccess); $result = mysql_affected_rows($this->mySQLaccess);
$this->dbError('db_Update');
if ($result == -1) { return false; } // Error return from mysql_affected_rows if ($result == -1) { return false; } // Error return from mysql_affected_rows
return $result; return $result;
} }
else else
{ {
$this->dbError("db_Update ($query)"); $this->dbError("db_Update ({$query})");
return FALSE; return FALSE;
} }
} }
@@ -501,6 +533,7 @@ class db {
$arg is usually a 'WHERE' clause $arg is usually a 'WHERE' clause
The way the code is written at the moment, a call to db_Update() with just the first two parameters specified can be The way the code is written at the moment, a call to db_Update() with just the first two parameters specified can be
converted simply by changing the function name - it will still work. converted simply by changing the function name - it will still work.
Deprecated routine - use db_Update() with array parameters
*/ */
function db_UpdateArray($table, $vars, $arg='', $debug = FALSE, $log_type = '', $log_remark = '') function db_UpdateArray($table, $vars, $arg='', $debug = FALSE, $log_type = '', $log_remark = '')
{ {
@@ -549,18 +582,23 @@ class db {
* *
* @access public * @access public
*/ */
function db_Fetch($type = MYSQL_ASSOC) { function db_Fetch($type = MYSQL_ASSOC)
{
global $eTraffic; global $eTraffic;
if (!(is_int($type))) { if (!(is_int($type)))
{
$type=MYSQL_ASSOC; $type=MYSQL_ASSOC;
} }
$b = microtime(); $b = microtime();
$row = @mysql_fetch_array($this->mySQLresult,$type); $row = @mysql_fetch_array($this->mySQLresult,$type);
$eTraffic->Bump('db_Fetch', $b); $eTraffic->Bump('db_Fetch', $b);
if ($row) { if ($row)
{
$this->dbError('db_Fetch'); $this->dbError('db_Fetch');
return $row; return $row;
} else { }
else
{
$this->dbError('db_Fetch'); $this->dbError('db_Fetch');
return FALSE; return FALSE;
} }
@@ -578,31 +616,42 @@ class db {
* *
* @access public * @access public
*/ */
function db_Count($table, $fields = '(*)', $arg = '', $debug = FALSE, $log_type = '', $log_remark = '') { function db_Count($table, $fields = '(*)', $arg = '', $debug = FALSE, $log_type = '', $log_remark = '')
{
$table = $this->db_IsLang($table); $table = $this->db_IsLang($table);
if ($fields == 'generic') { if ($fields == 'generic')
{
$query=$table; $query=$table;
if ($this->mySQLresult = $this->db_Query($query, NULL, 'db_Count', $debug, $log_type, $log_remark)) { if ($this->mySQLresult = $this->db_Query($query, NULL, 'db_Count', $debug, $log_type, $log_remark))
{
$rows = $this->mySQLrows = @mysql_fetch_array($this->mySQLresult); $rows = $this->mySQLrows = @mysql_fetch_array($this->mySQLresult);
$this->dbError('db_Count');
return $rows['COUNT(*)']; return $rows['COUNT(*)'];
} else { }
$this->dbError("dbCount ($query)"); else
{
$this->dbError("db_Count ({$query})");
return FALSE; return FALSE;
} }
} }
$this->mySQLcurTable = $table; $this->mySQLcurTable = $table;
$query='SELECT COUNT'.$fields.' FROM '.$this->mySQLPrefix.$table.' '.$arg; $query='SELECT COUNT'.$fields.' FROM '.$this->mySQLPrefix.$table.' '.$arg;
if ($this->mySQLresult = $this->db_Query($query, NULL, 'db_Count', $debug, $log_type, $log_remark)) { if ($this->mySQLresult = $this->db_Query($query, NULL, 'db_Count', $debug, $log_type, $log_remark))
{
$rows = $this->mySQLrows = @mysql_fetch_array($this->mySQLresult); $rows = $this->mySQLrows = @mysql_fetch_array($this->mySQLresult);
$this->dbError('db_Count');
return $rows[0]; return $rows[0];
} else { }
$this->dbError("dbCount ($query)"); else
{
$this->dbError("db_Count({$query})");
return FALSE; return FALSE;
} }
} }
/** /**
* @return void * @return void
* @desc Closes the mySQL server connection.<br /> * @desc Closes the mySQL server connection.<br />
@@ -615,7 +664,8 @@ class db {
* *
* @access public * @access public
*/ */
function db_Close() { function db_Close()
{
global $eTraffic; global $eTraffic;
if(!$this->mySQLaccess) if(!$this->mySQLaccess)
{ {
@@ -627,6 +677,7 @@ class db {
$this->dbError('dbClose'); $this->dbError('dbClose');
} }
/** /**
* @return int number of affected rows, or false on error * @return int number of affected rows, or false on error
* @param string $table * @param string $table
@@ -638,7 +689,8 @@ class db {
* <br /> * <br />
* @access public * @access public
*/ */
function db_Delete($table, $arg = '', $debug = FALSE, $log_type = '', $log_remark = '') { function db_Delete($table, $arg = '', $debug = FALSE, $log_type = '', $log_remark = '')
{
$table = $this->db_IsLang($table); $table = $this->db_IsLang($table);
$this->mySQLcurTable = $table; $this->mySQLcurTable = $table;
@@ -649,49 +701,48 @@ class db {
} }
if (!$arg) { if (!$arg)
if ($result = $this->mySQLresult = $this->db_Query('DELETE FROM '.$this->mySQLPrefix.$table, NULL, 'db_Delete', $debug, $log_type, $log_remark)) { {
if ($result = $this->mySQLresult = $this->db_Query('DELETE FROM '.$this->mySQLPrefix.$table, NULL, 'db_Delete', $debug, $log_type, $log_remark))
{
$this->dbError('db_Delete');
return $result; return $result;
} else { }
$this->dbError("db_Delete ($arg)"); else
{
$this->dbError("db_Delete({$arg})");
return FALSE; return FALSE;
} }
} else { }
if ($result = $this->mySQLresult = $this->db_Query('DELETE FROM '.$this->mySQLPrefix.$table.' WHERE '.$arg, NULL, 'db_Delete', $debug, $log_type, $log_remark)) { else
{
if ($result = $this->mySQLresult = $this->db_Query('DELETE FROM '.$this->mySQLPrefix.$table.' WHERE '.$arg, NULL, 'db_Delete', $debug, $log_type, $log_remark))
{
$tmp = mysql_affected_rows($this->mySQLaccess); $tmp = mysql_affected_rows($this->mySQLaccess);
$this->dbError('db_Delete');
return $tmp; return $tmp;
} else { }
else
{
$this->dbError('db_Delete ('.$arg.')'); $this->dbError('db_Delete ('.$arg.')');
return FALSE; return FALSE;
} }
} }
} }
/** /**
* @return unknown * @return unknown
* @desc Enter description here... * @desc Enter description here...
* @access private * @access private
*/ */
function db_Rows() { function db_Rows()
{
$rows = $this->mySQLrows = @mysql_num_rows($this->mySQLresult); $rows = $this->mySQLrows = @mysql_num_rows($this->mySQLresult);
$this->dbError('db_Rows'); $this->dbError('db_Rows');
return $rows; return $rows;
} }
/**
* @return unknown
* @param unknown $from
* @desc Enter description here...
* @access private
*/
function dbError($from) {
if ($error_message = @mysql_error()) {
if ($this->mySQLerror == TRUE) {
message_handler('ADMIN_MESSAGE', '<b>mySQL Error!</b> Function: '.$from.'. ['.@mysql_errno().' - '.$error_message.']', __LINE__, __FILE__);
return $error_message;
}
}
}
/** /**
* @return void * @return void
@@ -699,7 +750,8 @@ class db {
* @desc Enter description here... * @desc Enter description here...
* @access private * @access private
*/ */
function db_SetErrorReporting($mode) { function db_SetErrorReporting($mode)
{
$this->mySQLerror = $mode; $this->mySQLerror = $mode;
} }
@@ -712,37 +764,30 @@ class db {
*/ */
function db_Select_gen($query, $debug = FALSE, $log_type = '', $log_remark = '') function db_Select_gen($query, $debug = FALSE, $log_type = '', $log_remark = '')
{ {
/*
changes by jalist 19/01/05:
added string replace on table prefix to tidy up long database queries
usage: instead of sending "SELECT * FROM ".$this->mySQLPrefix."table", do "SELECT * FROM #table"
Returns result compatible with mysql_query - may be TRUE for some results, resource ID for others
*/
$this->tabset = FALSE; $this->tabset = FALSE;
if(strpos($query,'`#') !== FALSE) if(strpos($query,'`#') !== FALSE)
{ {
$query = preg_replace_callback("/\s`#([\w]*?)`\W/", array($this, 'ml_check'), $query); $query = preg_replace_callback("/\s`#([\w]*?)`\W/", array($this, 'ml_check'), $query);
} }
elseif(strpos($query,'#') !== FALSE) elseif(strpos($query,'#') !== FALSE)
{ {
$query = preg_replace_callback("/\s#([\w]*?)\W/", array($this, 'ml_check'), $query); $query = preg_replace_callback("/\s#([\w]*?)\W/", array($this, 'ml_check'), $query);
} }
if (($this->mySQLresult = $this->db_Query($query, NULL, 'db_Select_gen', $debug, $log_type, $log_remark)) === TRUE) if (($this->mySQLresult = $this->db_Query($query, NULL, 'db_Select_gen', $debug, $log_type, $log_remark)) === TRUE)
{ // Successful query which doesn't return a row count { // Successful query which doesn't return a row count
$this->dbError('db_Select_gen'); $this->dbError('db_Select_gen');
return TRUE; return TRUE;
} }
elseif ($this->mySQLresult === FALSE) elseif ($this->mySQLresult === FALSE)
{ // Failed query { // Failed query
$this->dbError('dbQuery ('.$query.')'); $this->dbError('db_Select_gen('.$query.')');
return FALSE; return FALSE;
} }
else else
{ // Successful query which does return a row count - get the count and return it { // Successful query which does return a row count - get the count and return it
$this->dbError('db_Select_gen'); $this->dbError('db_Select_gen');
return $this->db_Rows(); return $this->db_Rows();
} }
} }
@@ -764,27 +809,32 @@ class db {
* @desc Enter description here... * @desc Enter description here...
* @access private * @access private
*/ */
function db_Fieldname($offset) { function db_Fieldname($offset)
{
$result = @mysql_field_name($this->mySQLresult, $offset); $result = @mysql_field_name($this->mySQLresult, $offset);
return $result; return $result;
} }
/**
* @return unknown
* @desc Enter description here...
* @access private
*/
function db_Field_info() {
$result = @mysql_fetch_field($this->mySQLresult);
return $result;
}
/** /**
* @return unknown * @return unknown
* @desc Enter description here... * @desc Enter description here...
* @access private * @access private
*/ */
function db_Num_fields() { function db_Field_info()
{
$result = @mysql_fetch_field($this->mySQLresult);
return $result;
}
/**
* @return unknown
* @desc Enter description here...
* @access private
*/
function db_Num_fields()
{
$result = @mysql_num_fields($this->mySQLresult); $result = @mysql_num_fields($this->mySQLresult);
return $result; return $result;
} }
@@ -795,9 +845,11 @@ class db {
* @desc Enter description here... * @desc Enter description here...
* @access private * @access private
*/ */
function db_IsLang($table,$multiple=FALSE) { function db_IsLang($table,$multiple=FALSE)
{
global $pref, $mySQLtablelist; global $pref, $mySQLtablelist;
if ((!$this->mySQLlanguage || !$pref['multilanguage']) && $multiple==FALSE) { if ((!$this->mySQLlanguage || !$pref['multilanguage']) && $multiple==FALSE)
{
return $table; return $table;
} }
@@ -807,9 +859,11 @@ class db {
$this->mySQLaccess = $db_ConnectionID; $this->mySQLaccess = $db_ConnectionID;
} }
if (!$mySQLtablelist) { if (!$mySQLtablelist)
{
$tablist = mysql_list_tables($this->mySQLdefaultdb,$this->mySQLaccess); $tablist = mysql_list_tables($this->mySQLdefaultdb,$this->mySQLaccess);
while (list($temp) = mysql_fetch_array($tablist)) { while (list($temp) = mysql_fetch_array($tablist))
{
$mySQLtablelist[] = $temp; $mySQLtablelist[] = $temp;
} }
} }
@@ -818,17 +872,23 @@ class db {
// ---- Find all multi-language tables. // ---- Find all multi-language tables.
if($multiple == TRUE){ // return an array of all matching language tables. eg [french]->e107_lan_news if($multiple == TRUE)
if(!is_array($table)){ { // return an array of all matching language tables. eg [french]->e107_lan_news
if(!is_array($table))
{
$table = array($table); $table = array($table);
} }
foreach($mySQLtablelist as $tab){ foreach($mySQLtablelist as $tab)
if(stristr($tab, $this->mySQLPrefix."lan_") !== FALSE){ {
if(stristr($tab, $this->mySQLPrefix."lan_") !== FALSE)
{
$tmp = explode("_",str_replace($this->mySQLPrefix."lan_","",$tab)); $tmp = explode("_",str_replace($this->mySQLPrefix."lan_","",$tab));
$lng = $tmp[0]; $lng = $tmp[0];
foreach($table as $t){ foreach($table as $t)
if(eregi($t."$",$tab)){ {
if(eregi($t."$",$tab))
{
$lanlist[$lng][$this->mySQLPrefix.$t] = $tab; $lanlist[$lng][$this->mySQLPrefix.$t] = $tab;
} }
} }
@@ -838,7 +898,8 @@ class db {
} }
// ------------------------- // -------------------------
if (in_array($this->mySQLPrefix.$mltable, $mySQLtablelist)) { if (in_array($this->mySQLPrefix.$mltable, $mySQLtablelist))
{
return $mltable; return $mltable;
} }
return $table; return $table;
@@ -850,14 +911,18 @@ class db {
* @desc returns fields as structured array * @desc returns fields as structured array
* @access public * @access public
*/ */
function db_getList($fields = 'ALL', $amount = FALSE, $maximum = FALSE, $ordermode=FALSE) { function db_getList($fields = 'ALL', $amount = FALSE, $maximum = FALSE, $ordermode=FALSE)
{
$list = array(); $list = array();
$counter = 1; $counter = 1;
while ($row = $this->db_Fetch()) { while ($row = $this->db_Fetch())
foreach($row as $key => $value) { {
if (is_string($key)) { foreach($row as $key => $value)
if (strtoupper($fields) == 'ALL' || in_array ($key, $fields)) { {
if (is_string($key))
{
if (strtoupper($fields) == 'ALL' || in_array ($key, $fields))
{
if(!$ordermode) if(!$ordermode)
{ {
$list[$counter][$key] = $value; $list[$counter][$key] = $value;
@@ -869,7 +934,8 @@ class db {
} }
} }
} }
if ($amount && $amount == $counter || ($maximum && $counter > $maximum)) { if ($amount && $amount == $counter || ($maximum && $counter > $maximum))
{
break; break;
} }
$counter++; $counter++;
@@ -882,7 +948,8 @@ class db {
* @desc returns total number of queries made so far * @desc returns total number of queries made so far
* @access public * @access public
*/ */
function db_QueryCount() { function db_QueryCount()
{
global $db_mySQLQueryCount; global $db_mySQLQueryCount;
return $db_mySQLQueryCount; return $db_mySQLQueryCount;
} }
@@ -891,36 +958,42 @@ class db {
/* /*
Multi-language Query Function. Multi-language Query Function.
*/ */
function db_Query_all($query,$debug="")
{
function db_Query_all($query,$debug=""){
$error = ""; $error = "";
$query = str_replace("#",$this->mySQLPrefix,$query); $query = str_replace("#",$this->mySQLPrefix,$query);
if(!$this->db_Query($query)){ // run query on the default language first. if(!$this->db_Query($query))
{ // run query on the default language first.
$error .= $query. " failed"; $error .= $query. " failed";
} }
$tmp = explode(" ",$query); $tmp = explode(" ",$query);
foreach($tmp as $val){ foreach($tmp as $val)
if(strpos($val,$this->mySQLPrefix) !== FALSE){ {
if(strpos($val,$this->mySQLPrefix) !== FALSE)
{
$table[] = str_replace($this->mySQLPrefix,"",$val); $table[] = str_replace($this->mySQLPrefix,"",$val);
$search[] = $val; $search[] = $val;
} }
} }
// Loop thru relevant language tables and replace each tablename within the query. // Loop thru relevant language tables and replace each tablename within the query.
if($tablist = $this->db_IsLang($table,TRUE)){ if($tablist = $this->db_IsLang($table,TRUE))
foreach($tablist as $key=>$tab){ {
foreach($tablist as $key=>$tab)
{
$querylan = $query; $querylan = $query;
foreach($search as $find){ foreach($search as $find)
{
$lang = $key; $lang = $key;
$replace = ($tab[$find] !="") ? $tab[$find] : $find; $replace = ($tab[$find] !="") ? $tab[$find] : $find;
$querylan = str_replace($find,$replace,$querylan); $querylan = str_replace($find,$replace,$querylan);
} }
if(!$this->db_Query($querylan)){ // run query on other language tables. if(!$this->db_Query($querylan))
{ // run query on other language tables.
$error .= $querylan." failed for language"; $error .= $querylan." failed for language";
} }
if($debug){ echo "<br />** lang= ".$querylan; } if($debug){ echo "<br />** lang= ".$querylan; }
@@ -931,52 +1004,54 @@ class db {
return ($error)? FALSE : TRUE; return ($error)? FALSE : TRUE;
} }
// Determines if a plugin field (and key) exist. OR if fieldid is numeric - return the field name in that position. // Determines if a plugin field (and key) exist. OR if fieldid is numeric - return the field name in that position.
// If $retinfo is true, returns complete array of field data; FALSE if not found // If $retinfo is true, returns complete array of field data; FALSE if not found
function db_Field($table,$fieldid="",$key="", $retinfo = FALSE) function db_Field($table,$fieldid="",$key="", $retinfo = FALSE)
{ {
if(!$this->mySQLdefaultdb) if(!$this->mySQLdefaultdb)
{ {
global $mySQLdefaultdb; global $mySQLdefaultdb;
$this->mySQLdefaultdb = $mySQLdefaultdb; $this->mySQLdefaultdb = $mySQLdefaultdb;
} }
$convert = array("PRIMARY"=>"PRI","INDEX"=>"MUL","UNIQUE"=>"UNI"); $convert = array("PRIMARY"=>"PRI","INDEX"=>"MUL","UNIQUE"=>"UNI");
$key = ($convert[$key]) ? $convert[$key] : "OFF"; $key = ($convert[$key]) ? $convert[$key] : "OFF";
if(!$this->mySQLaccess) if(!$this->mySQLaccess)
{ {
global $db_ConnectionID; global $db_ConnectionID;
$this->mySQLaccess = $db_ConnectionID; $this->mySQLaccess = $db_ConnectionID;
} }
$result = mysql_query("SHOW COLUMNS FROM ".$this->mySQLPrefix.$table,$this->mySQLaccess); $result = mysql_query("SHOW COLUMNS FROM ".$this->mySQLPrefix.$table,$this->mySQLaccess);
if (mysql_num_rows($result) > 0) if (mysql_num_rows($result) > 0)
{ {
$c=0; $c=0;
while ($row = mysql_fetch_assoc($result)) while ($row = mysql_fetch_assoc($result))
{
if(is_numeric($fieldid))
{ {
if($c == $fieldid) if(is_numeric($fieldid))
{ {
if ($retinfo) return $row; if($c == $fieldid)
return $row['Field']; // field number matches. {
} if ($retinfo) return $row;
return $row['Field']; // field number matches.
}
}
else
{ // Check for match of key name - and allow that key might not be used
if(($fieldid == $row['Field']) && (($key == "OFF") || ($key == $row['Key'])))
{
if ($retinfo) return $row;
return TRUE;
}
}
$c++;
} }
else
{ // Check for match of key name - and allow that key might not be used
if(($fieldid == $row['Field']) && (($key == "OFF") || ($key == $row['Key'])))
{
if ($retinfo) return $row;
return TRUE;
}
}
$c++;
}
} }
return FALSE; return FALSE;
} }
/** /**
* A pointer to mysql_real_escape_string() - see http://www.php.net/mysql_real_escape_string * A pointer to mysql_real_escape_string() - see http://www.php.net/mysql_real_escape_string
* *
@@ -999,6 +1074,7 @@ class db {
return mysql_real_escape_string($data,$this->mySQLaccess); return mysql_real_escape_string($data,$this->mySQLaccess);
} }
/* /*
* Verify whether a table exists, without causing an error * Verify whether a table exists, without causing an error
* *
@@ -1008,13 +1084,48 @@ class db {
* NOTES: the 'official' way to do this uses SHOW TABLE STATUS, but that is 20x slower! * NOTES: the 'official' way to do this uses SHOW TABLE STATUS, but that is 20x slower!
* LIMIT 0 is 3x slower than LIMIT 1 * LIMIT 0 is 3x slower than LIMIT 1
*/ */
function db_Table_exists($table){ function db_Table_exists($table)
{
$res = $this->db_Query("SELECT 1 FROM ".$this->mySQLPrefix.$table." LIMIT 1"); // error if not there $res = $this->db_Query("SELECT 1 FROM ".$this->mySQLPrefix.$table." LIMIT 1"); // error if not there
if ($res) return TRUE; if ($res) return TRUE;
return FALSE; return FALSE;
} }
/**
* @return text string relating to error (empty string if no error)
* @param unknown $from
* @desc Calling method from within this class
* @access private
*/
function dbError($from)
{
$this->mySQLlastErrNum = mysql_errno();
$this->mySQLlastErrText = '';
if ($this->mySQLlastErrNum == 0)
{
return '';
}
$this->mySQLlastErrText = mysql_error(); // Get the error text.
if ($this->mySQLerror == TRUE)
{
message_handler('ADMIN_MESSAGE', '<b>mySQL Error!</b> Function: '.$from.'. ['.$this->mySQLlastErrNum.' - '.$this->mySQLlastErrText.']', __LINE__, __FILE__);
}
return $this->mySQLlastErrText;
}
// Return error number for last operation
function getLastErrorNumber()
{
return $this->mySQLlastErrNum; // Number of last error
}
// Return error text for last operation
function getLastErrorText()
{
return $this->mySQLlastErrText; // Text of last error (empty string if no error)
}
} }
?> ?>

View File

@@ -9,9 +9,9 @@
* News handler * News handler
* *
* $Source: /cvs_backup/e107_0.8/e107_handlers/news_class.php,v $ * $Source: /cvs_backup/e107_0.8/e107_handlers/news_class.php,v $
* $Revision: 1.13 $ * $Revision: 1.14 $
* $Date: 2009-01-25 17:44:13 $ * $Date: 2009-05-24 15:34:37 $
* $Author: mcfly_e107 $ * $Author: e107steved $
*/ */
if (!defined('e107_INIT')) { exit; } if (!defined('e107_INIT')) { exit; }
@@ -49,11 +49,16 @@ class news {
} }
else else
{ {
$message = "<strong>".(!mysql_errno() ? LAN_NEWS_46 : LAN_NEWS_5)."</strong>"; if($sql->getLastErrorNumber())
if(mysql_errno()) {
$emessage->add(LAN_NEWS_5, E_MESSAGE_ERROR, $smessages); $emessage->add(LAN_NEWS_5, E_MESSAGE_ERROR, $smessages);
$message = "<strong>".LAN_NEWS_5."</strong>";
}
else else
{
$emessage->add(LAN_NEWS_46, E_MESSAGE_INFO, $smessages); $emessage->add(LAN_NEWS_46, E_MESSAGE_INFO, $smessages);
$message = "<strong>".LAN_NEWS_46."</strong>";
}
} }
@@ -69,8 +74,8 @@ class news {
$message = LAN_NEWS_6; $message = LAN_NEWS_6;
$emessage->add(LAN_NEWS_6, E_MESSAGE_SUCCESS, $smessages); $emessage->add(LAN_NEWS_6, E_MESSAGE_SUCCESS, $smessages);
$e107cache -> clear('news.php'); $e107cache -> clear('news.php');
$id = mysql_insert_id(); // $id = mysql_insert_id();
$data = array('method'=>'create', 'table'=>'news', 'id'=>$id, 'plugin'=>'news', 'function'=>'submit_item'); $data = array('method'=>'create', 'table'=>'news', 'id'=>$news['news_id'], 'plugin'=>'news', 'function'=>'submit_item');
//moved down - prevent wrong mysql_insert_id //moved down - prevent wrong mysql_insert_id
$admin_log->logArrayAll('NEWS_08', $news); $admin_log->logArrayAll('NEWS_08', $news);
@@ -89,8 +94,8 @@ class news {
if($pref['trackbackEnabled']) if($pref['trackbackEnabled'])
{ {
$excerpt = substr($news['news_body'], 0, 100)."..."; $excerpt = substr($news['news_body'], 0, 100)."...";
$id=mysql_insert_id(); // $id=mysql_insert_id();
$permLink = $e107->base_path."comment.php?comment.news.{$id}"; $permLink = $e107->base_path."comment.php?comment.news.{$news['news_id']}";
require_once(e_PLUGIN."trackback/trackbackClass.php"); require_once(e_PLUGIN."trackback/trackbackClass.php");
$trackback = new trackbackClass(); $trackback = new trackbackClass();
@@ -98,12 +103,15 @@ class news {
if($_POST['trackback_urls']) if($_POST['trackback_urls'])
{ {
$urlArray = explode("\n", $_POST['trackback_urls']); $urlArray = explode("\n", $_POST['trackback_urls']);
foreach($urlArray as $pingurl) { foreach($urlArray as $pingurl)
{
if(!$error = $trackback -> sendTrackback($permLink, $pingurl, $news['news_title'], $excerpt)) if(!$error = $trackback -> sendTrackback($permLink, $pingurl, $news['news_title'], $excerpt))
{ {
$message .= "<br />successfully pinged {$pingurl}."; $message .= "<br />successfully pinged {$pingurl}.";
$emessage->add("Successfully pinged {$pingurl}.", E_MESSAGE_SUCCESS, $smessages); $emessage->add("Successfully pinged {$pingurl}.", E_MESSAGE_SUCCESS, $smessages);
} else { }
else
{
$message .= "<br />was unable to ping {$pingurl}<br />[ Error message returned was : '{$error}'. ]"; $message .= "<br />was unable to ping {$pingurl}<br />[ Error message returned was : '{$error}'. ]";
$emessage->add("was unable to ping {$pingurl}<br />[ Error message returned was : '{$error}'. ]", E_MESSAGE_ERROR, $smessages); $emessage->add("was unable to ping {$pingurl}<br />[ Error message returned was : '{$error}'. ]", E_MESSAGE_ERROR, $smessages);
} }