mirror of
https://github.com/e107inc/e107.git
synced 2025-08-03 13:17:24 +02:00
Bugtracker #3985 - more improvements to DB class, pluss bring 0.7 and 0.8 mysql_class.php pretty much in line
This commit is contained in:
@@ -4,7 +4,7 @@
|
|||||||
+---------------------------------------------------------------+
|
+---------------------------------------------------------------+
|
||||||
| e107 website system
|
| e107 website system
|
||||||
|
|
|
|
||||||
| Steve Dunstan 2001-2002
|
| <EFBFBD>Steve Dunstan 2001-2002
|
||||||
| http://e107.org
|
| http://e107.org
|
||||||
| jalist@e107.org
|
| jalist@e107.org
|
||||||
|
|
|
|
||||||
@@ -12,9 +12,10 @@
|
|||||||
| GNU General Public License (http://gnu.org).
|
| GNU General Public License (http://gnu.org).
|
||||||
|
|
|
|
||||||
| $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.14 $
|
| $Revision: 1.15 $
|
||||||
| $Date: 2007-06-15 08:04:07 $
|
| $Date: 2007-06-26 21:34:24 $
|
||||||
| $Author: e107coders $
|
| $Author: e107steved $
|
||||||
|
|
|
||||||
+----------------------------------------------------------------------------+
|
+----------------------------------------------------------------------------+
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -23,12 +24,14 @@ if (!defined('e107_INIT')) { exit; }
|
|||||||
$db_time = 0.0; // Global total time spent in all db object queries
|
$db_time = 0.0; // Global total time spent in all db object queries
|
||||||
$db_mySQLQueryCount = 0; // Global total number of db object queries (all db's)
|
$db_mySQLQueryCount = 0; // Global total number of db object queries (all db's)
|
||||||
|
|
||||||
|
$db_ConnectionID = NULL;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* MySQL Abstraction class
|
* MySQL Abstraction class
|
||||||
*
|
*
|
||||||
* @package e107
|
* @package e107
|
||||||
* @version $Revision: 1.14 $
|
* @version $Revision: 1.15 $
|
||||||
* @author $Author: e107coders $
|
* @author $Author: e107steved $
|
||||||
*/
|
*/
|
||||||
class db {
|
class db {
|
||||||
|
|
||||||
@@ -81,8 +84,9 @@ class db {
|
|||||||
*
|
*
|
||||||
* @access public
|
* @access public
|
||||||
*/
|
*/
|
||||||
function db_Connect($mySQLserver, $mySQLuser, $mySQLpassword, $mySQLdefaultdb) {
|
function db_Connect($mySQLserver, $mySQLuser, $mySQLpassword, $mySQLdefaultdb)
|
||||||
global $eTraffic;
|
{
|
||||||
|
global $eTraffic, $db_ConnectionID;
|
||||||
$eTraffic->BumpWho('db Connect', 1);
|
$eTraffic->BumpWho('db Connect', 1);
|
||||||
|
|
||||||
$this->mySQLserver = $mySQLserver;
|
$this->mySQLserver = $mySQLserver;
|
||||||
@@ -113,6 +117,7 @@ class db {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
$db_ConnectionID = $this->mySQLaccess; // Save the connection resource
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -158,6 +163,7 @@ class db {
|
|||||||
* @param unknown $rli
|
* @param unknown $rli
|
||||||
* @desc Enter description here...
|
* @desc Enter description here...
|
||||||
* @access private
|
* @access private
|
||||||
|
* 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;
|
||||||
@@ -176,8 +182,8 @@ class db {
|
|||||||
|
|
||||||
if(!$this->mySQLaccess)
|
if(!$this->mySQLaccess)
|
||||||
{
|
{
|
||||||
global $sql;
|
global $db_ConnectionID;
|
||||||
$this->mySQLaccess = $sql->mySQLaccess;
|
$this->mySQLaccess = $db_ConnectionID;
|
||||||
}
|
}
|
||||||
|
|
||||||
$b = microtime();
|
$b = microtime();
|
||||||
@@ -289,8 +295,8 @@ class db {
|
|||||||
|
|
||||||
if(!$this->mySQLaccess)
|
if(!$this->mySQLaccess)
|
||||||
{
|
{
|
||||||
global $sql;
|
global $db_ConnectionID;
|
||||||
$this->mySQLaccess = $sql->mySQLaccess;
|
$this->mySQLaccess = $db_ConnectionID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -327,8 +333,8 @@ class db {
|
|||||||
|
|
||||||
if(!$this->mySQLaccess)
|
if(!$this->mySQLaccess)
|
||||||
{
|
{
|
||||||
global $sql;
|
global $db_ConnectionID;
|
||||||
$this->mySQLaccess = $sql->mySQLaccess;
|
$this->mySQLaccess = $db_ConnectionID;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($result = $this->mySQLresult = $this->db_Query('UPDATE '.MPREFIX.$table.' SET '.$arg, NULL, 'db_Update', $debug, $log_type, $log_remark)) {
|
if ($result = $this->mySQLresult = $this->db_Query('UPDATE '.MPREFIX.$table.' SET '.$arg, NULL, 'db_Update', $debug, $log_type, $log_remark)) {
|
||||||
@@ -353,10 +359,10 @@ class db {
|
|||||||
*
|
*
|
||||||
* @access public
|
* @access public
|
||||||
*/
|
*/
|
||||||
function db_Fetch() {
|
function db_Fetch($type = MYSQL_BOTH) {
|
||||||
global $eTraffic;
|
global $eTraffic;
|
||||||
$b = microtime();
|
$b = microtime();
|
||||||
$row = @mysql_fetch_array($this->mySQLresult);
|
$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');
|
||||||
@@ -420,8 +426,8 @@ class db {
|
|||||||
global $eTraffic;
|
global $eTraffic;
|
||||||
if(!$this->mySQLaccess)
|
if(!$this->mySQLaccess)
|
||||||
{
|
{
|
||||||
global $sql;
|
global $db_ConnectionID;
|
||||||
$this->mySQLaccess = $sql->mySQLaccess;
|
$this->mySQLaccess = $db_ConnectionID;
|
||||||
}
|
}
|
||||||
$eTraffic->BumpWho('db Close', 1);
|
$eTraffic->BumpWho('db Close', 1);
|
||||||
mysql_close($this->mySQLaccess);
|
mysql_close($this->mySQLaccess);
|
||||||
@@ -445,8 +451,8 @@ class db {
|
|||||||
|
|
||||||
if(!$this->mySQLaccess)
|
if(!$this->mySQLaccess)
|
||||||
{
|
{
|
||||||
global $sql;
|
global $db_ConnectionID;
|
||||||
$this->mySQLaccess = $sql->mySQLaccess;
|
$this->mySQLaccess = $db_ConnectionID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -523,12 +529,12 @@ class db {
|
|||||||
$this->tabset = FALSE;
|
$this->tabset = FALSE;
|
||||||
if(strpos($query,'`#') !== FALSE)
|
if(strpos($query,'`#') !== FALSE)
|
||||||
{
|
{
|
||||||
$query = preg_replace_callback("/\s`#([\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
|
||||||
@@ -555,10 +561,7 @@ class db {
|
|||||||
$this->mySQLcurTable = $table;
|
$this->mySQLcurTable = $table;
|
||||||
$this->tabset = true;
|
$this->tabset = true;
|
||||||
}
|
}
|
||||||
$ret = str_replace("#", MPREFIX, $matches[0]);
|
return ' `'.MPREFIX.$table.'`'.substr($matches[0],-1);
|
||||||
$ret = str_replace($matches[0], $table, $ret);
|
|
||||||
// return $ret; // this one fails.
|
|
||||||
return " ".MPREFIX.$table.substr($matches[0],-1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -607,8 +610,8 @@ class db {
|
|||||||
|
|
||||||
if(!$this->mySQLaccess)
|
if(!$this->mySQLaccess)
|
||||||
{
|
{
|
||||||
global $sql;
|
global $db_ConnectionID;
|
||||||
$this->mySQLaccess = $sql->mySQLaccess;
|
$this->mySQLaccess = $db_ConnectionID;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$mySQLtablelist) {
|
if (!$mySQLtablelist) {
|
||||||
@@ -746,8 +749,8 @@ class db {
|
|||||||
|
|
||||||
if(!$this->mySQLaccess)
|
if(!$this->mySQLaccess)
|
||||||
{
|
{
|
||||||
global $sql;
|
global $db_ConnectionID;
|
||||||
$this->mySQLaccess = $sql->mySQLaccess;
|
$this->mySQLaccess = $db_ConnectionID;
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = mysql_query("SHOW COLUMNS FROM ".MPREFIX.$table,$this->mySQLaccess);
|
$result = mysql_query("SHOW COLUMNS FROM ".MPREFIX.$table,$this->mySQLaccess);
|
||||||
@@ -787,15 +790,17 @@ class db {
|
|||||||
* @param string $data
|
* @param string $data
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
function escape($data, $strip = true) {
|
function escape($data, $strip = true)
|
||||||
if ($strip) {
|
{
|
||||||
|
if ($strip)
|
||||||
|
{
|
||||||
$data = strip_if_magic($data);
|
$data = strip_if_magic($data);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!$this->mySQLaccess)
|
if(!$this->mySQLaccess)
|
||||||
{
|
{
|
||||||
global $sql;
|
global $db_ConnectionID;
|
||||||
$this->mySQLaccess = $sql->mySQLaccess;
|
$this->mySQLaccess = $db_ConnectionID;
|
||||||
}
|
}
|
||||||
|
|
||||||
return mysql_real_escape_string($data,$this->mySQLaccess);
|
return mysql_real_escape_string($data,$this->mySQLaccess);
|
||||||
|
@@ -11,8 +11,8 @@
|
|||||||
| GNU General Public License (http://gnu.org).
|
| GNU General Public License (http://gnu.org).
|
||||||
|
|
|
|
||||||
| $Source: /cvs_backup/e107_0.8/e107_plugins/forum/forum_post.php,v $
|
| $Source: /cvs_backup/e107_0.8/e107_plugins/forum/forum_post.php,v $
|
||||||
| $Revision: 1.7 $
|
| $Revision: 1.8 $
|
||||||
| $Date: 2007-06-21 19:37:13 $
|
| $Date: 2007-06-26 21:34:34 $
|
||||||
| $Author: e107steved $
|
| $Author: e107steved $
|
||||||
+----------------------------------------------------------------------------+
|
+----------------------------------------------------------------------------+
|
||||||
*/
|
*/
|
||||||
@@ -448,21 +448,24 @@ if (!$FORUMPOST)
|
|||||||
}
|
}
|
||||||
/* check post access (bugtracker #1424) */
|
/* check post access (bugtracker #1424) */
|
||||||
|
|
||||||
if($action == "rp" && !$sql -> db_Select("forum_t", "*", "thread_id='$id'"))
|
if($action == "rp" && !$sql -> db_Select("forum_t", "*", "thread_id='{$id}'"))
|
||||||
{
|
{
|
||||||
$ns -> tablerender(LAN_20, "<div style='text-align:center'>".LAN_399."</div>");
|
$ns -> tablerender(LAN_20, "<div style='text-align:center'>".LAN_399."</div>");
|
||||||
require_once(FOOTERF);
|
require_once(FOOTERF);
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
else if($action == "nt" && !$sact && !$sql -> db_Select("forum", "*", "forum_id='$id'"))
|
elseif($action == "nt")
|
||||||
{
|
{
|
||||||
$ns -> tablerender(LAN_20, "<div style='text-align:center'>".LAN_399."</div>");
|
if (!$sact && !$sql -> db_Select("forum", "*", "forum_id='{$id}'"))
|
||||||
require_once(FOOTERF);
|
{
|
||||||
|
$ns -> tablerender(LAN_20, "<div style='text-align:center'>".LAN_399."</div>");
|
||||||
|
require_once(FOOTERF);
|
||||||
exit;
|
exit;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// DB access should pass - after all, the thread should exist
|
// DB access should pass - after all, the thread should exist
|
||||||
$sql->db_Select_gen("SELECT t.*, p.forum_postclass FROM #forum_t AS t
|
$sql->db_Select_gen("SELECT t.*, p.forum_postclass FROM #forum_t AS t
|
||||||
LEFT JOIN #forum AS p ON t.thread_forum_id=p.forum_id WHERE thread_id='{$id}'");
|
LEFT JOIN #forum AS p ON t.thread_forum_id=p.forum_id WHERE thread_id='{$id}'");
|
||||||
$fpr = $sql -> db_Fetch();
|
$fpr = $sql -> db_Fetch();
|
||||||
|
Reference in New Issue
Block a user