diff --git a/e107_handlers/mysql_class.php b/e107_handlers/mysql_class.php
index 75c5723df..b8b891a5f 100644
--- a/e107_handlers/mysql_class.php
+++ b/e107_handlers/mysql_class.php
@@ -67,7 +67,7 @@ class e_db_mysql implements e_db
protected $mySQLport = 3306;
public $mySQLPrefix;
- /** @var PDO */
+ /** @var resource */
protected $mySQLaccess;
public $mySQLresult;
public $mySQLrows;
@@ -91,9 +91,6 @@ class e_db_mysql implements e_db
public $mySqlServerInfo = '?'; // Server info - needed for various things
public $total_results = false; // Total number of results
-
- private $pdo = false; // using PDO or not.
- private $pdoBind= false;
/** @var e107_db_debug */
private $dbg;
@@ -106,15 +103,6 @@ class e_db_mysql implements e_db
*/
public function __construct()
{
-
- global $pref, $db_defaultPrefix;
-
-
- if((PHP_MAJOR_VERSION > 6) || !function_exists('mysql_connect') || (defined('e_PDO') && e_PDO === true))
- {
- $this->pdo = true;
- }
-
e107::getSingleton('e107_traffic')->BumpWho('Create db object', 1);
$this->mySQLPrefix = MPREFIX; // Set the default prefix - may be overridden
@@ -149,7 +137,7 @@ class e_db_mysql implements e_db
function getPDO()
{
- return $this->pdo;
+ return false;
}
function debugMode($bool)
@@ -196,29 +184,7 @@ class e_db_mysql implements e_db
$this->mySQLerror = false;
- if($this->pdo)
- {
-
- if(strpos($mySQLserver,':')!==false && substr_count($mySQLserver, ':')===1)
- {
- list($this->mySQLserver,$this->mySQLport) = explode(':',$mySQLserver,2);
- }
-
- try
- {
- $this->mySQLaccess = new PDO("mysql:host=".$this->mySQLserver."; port=".$this->mySQLport, $this->mySQLuser, $this->mySQLpassword, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
-
- }
- catch(PDOException $ex)
- {
- $this->mySQLlastErrText = $ex->getMessage();
- $this->mySQLlastErrNum = $ex->getCode();
-
- return 'e1';
- }
-
- }
- elseif(defined("USE_PERSISTANT_DB") && USE_PERSISTANT_DB == TRUE)
+ if(defined("USE_PERSISTANT_DB") && USE_PERSISTANT_DB == TRUE)
{
// No persistent link parameter permitted
if ( ! $this->mySQLaccess = @mysql_pconnect($this->mySQLserver, $this->mySQLuser, $this->mySQLpassword))
@@ -236,24 +202,18 @@ class e_db_mysql implements e_db
}
}
- $this->mySqlServerInfo = ($this->pdo) ? $this->mySQLaccess->query('select version()')->fetchColumn() : mysql_get_server_info(); // We always need this for db_Set_Charset() - so make generally available
+ $this->mySqlServerInfo = mysql_get_server_info(); // We always need this for db_Set_Charset() - so make generally available
// Set utf8 connection?
//@TODO: simplify when yet undiscovered side-effects will be fixed
$this->db_Set_Charset();
$this->setSQLMode();
- // if ($this->pdo!== true && !@mysql_select_db($this->mySQLdefaultdb, $this->mySQLaccess))
if (!$this->database($this->mySQLdefaultdb))
{
return 'e2';
}
- if($this->pdo == true)
- {
- // $this->mySQLaccess->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
- // $this->mySQLaccess->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true);
- }
$this->dbError('dbConnect/SelectDB');
// Save the connection resource
@@ -277,12 +237,12 @@ class e_db_mysql implements e_db
* @param string $mySQLdefaultdb The database schema to connect to
* @param string $newLink force a new link connection if TRUE. Default FALSE
* @param string $mySQLPrefix Tables prefix. Default to $mySQLPrefix from e107_config.php
- * @return boolean true on success, false on error.
+ * @return boolean true on success, false on error.
*/
public function connect($mySQLserver, $mySQLuser, $mySQLpassword, $newLink = false)
{
global $db_ConnectionID, $db_defaultPrefix;
-
+
e107::getSingleton('e107_traffic')->BumpWho('db Connect', 1);
$this->mySQLserver = $mySQLserver;
@@ -295,49 +255,19 @@ class e_db_mysql implements e_db
list($this->mySQLserver,$this->mySQLport) = explode(':',$mySQLserver,2);
}
- // if($this->mySQLserver === 'localhost') // problematic.
+ if (!$this->mySQLaccess = @mysql_connect($this->mySQLserver, $this->mySQLuser, $this->mySQLpassword, $newLink))
{
- // $this->mySQLserver = '127.0.0.1'; // faster by almost 1 second.
+ $this->mySQLlastErrText = mysql_error();
+ return false;
}
-
- if($this->pdo) // PDO
- {
- try
- {
- $this->mySQLaccess = new PDO("mysql:host=".$this->mySQLserver."; port=".$this->mySQLport, $this->mySQLuser, $this->mySQLpassword, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
- }
- catch(PDOException $ex)
- {
- $this->mySQLlastErrText = $ex->getMessage();
- $this->mySQLLastErrNum = $ex->getCode();
- $this->dbg->log($this->mySQLlastErrText); // Useful for Debug.
- return false;
- }
-
- // $this->mySqlServerInfo = $this->mySQLaccess->getAttribute(PDO::ATTR_SERVER_INFO);
- $this->mySqlServerInfo = $this->mySQLaccess->query('select version()')->fetchColumn();
-
- }
- else // Legacy.
- {
- if (!$this->mySQLaccess = @mysql_connect($this->mySQLserver, $this->mySQLuser, $this->mySQLpassword, $newLink))
- {
- $this->mySQLlastErrText = mysql_error();
- return false;
- }
-
- $this->mySqlServerInfo = mysql_get_server_info();
- }
+ $this->mySqlServerInfo = mysql_get_server_info();
$this->db_Set_Charset();
$this->setSQLMode();
-
- //if ($db_ConnectionID == NULL){
- $db_ConnectionID = $this->mySQLaccess;
- // }
-
+ $db_ConnectionID = $this->mySQLaccess;
+
return true;
}
@@ -355,11 +285,11 @@ class e_db_mysql implements e_db
/**
- * Select the database to use.
+ * Select the database to use.
* @param string $database name
* @param string $table prefix . eg. e107_
* @param boolean $multiple set to maintain connection to a secondary database.
- * @return boolean true when database selection was successful otherwise false.
+ * @return boolean true when database selection was successful otherwise false.
*/
public function database($database, $prefix = MPREFIX, $multiple=false)
{
@@ -372,31 +302,12 @@ class e_db_mysql implements e_db
return true;
}
- if($this->pdo)
- {
-
- try
- {
- $this->mySQLaccess->query("use `".$database."`");
- // $this->mySQLaccess->select_db($database); $dbh->query("use newdatabase");
- }
- catch (PDOException $e)
- {
- $this->mySQLlastErrText = $e->getMessage();
- $this->mySQLlastErrNum = $e->getCode();
- return false;
- }
-
- return true;
- }
-
-
if (!@mysql_select_db($database, $this->mySQLaccess))
{
return false;
}
-
- return true;
+
+ return true;
}
@@ -463,10 +374,8 @@ class e_db_mysql implements e_db
*
* If a SELECT query includes SQL_CALC_FOUND_ROWS, the value of FOUND_ROWS() is retrieved and stored in $this->total_results
* @param string|array $query
- * @param string $query['PREPARE'] PDO Format query.
- *@param array $query['BIND'] eg. array['my_field'] = array('value'=>'whatever', 'type'=>'str');
* @param object $rli
- * @return boolean|PDOStatement | resource - as mysql_query() function.
+ * @return boolean|resource - as mysql_query() function.
* FALSE indicates an error
* For SELECT, SHOW, DESCRIBE, EXPLAIN and others returning a result set, returns a resource
* TRUE indicates success in other cases
@@ -495,71 +404,11 @@ class e_db_mysql implements e_db
$this->provide_mySQLaccess();
$b = microtime();
-
- if($this->pdo)
- {
- if(is_array($query) && !empty($query['PREPARE']) && !empty($query['BIND']))
- {
- /** @var PDOStatement $prep */
- $prep = $this->mySQLaccess->prepare($query['PREPARE']);
- foreach($query['BIND'] as $k=>$v)
- {
- $prep->bindValue(':'.$k, $v['value'],$v['type']);
+ $sQryRes = is_null($rli) ? @mysql_query($query, $this->mySQLaccess) : @mysql_query($query, $rli);
+ $this->mySQLlastErrNum = mysql_errno();
+ $this->mySQLlastErrText = mysql_error();
- }
-
- try
- {
- $prep->execute();
- $sQryRes = $prep->rowCount();
- }
- catch(PDOException $ex)
- {
- $sQryRes = false;
- $this->mySQLlastErrText = $ex->getMessage();
- $this->mySQLlastErrNum = $ex->getCode();
- }
- }
- else
- {
- try
- {
-
- if(preg_match('#^(CREATE TABLE|DROP TABLE|ALTER TABLE|RENAME TABLE|CREATE DATABASE|CREATE INDEX)#',$query, $matches))
- {
- /** @var PDO $rli */
- $sQryRes = is_null($rli) ? $this->mySQLaccess->exec($query) : $rli->exec($query);
-
- if($sQryRes !==false)
- {
- $sQryRes = true; // match with non-PDO results.
- }
-
- }
- else
- {
- /** @var PDO $rli */
- $sQryRes = is_null($rli) ? $this->mySQLaccess->query($query) : $rli->query($query);
- }
-
- }
- catch(PDOException $ex)
- {
- $sQryRes = false;
- $this->mySQLlastErrText = $ex->getMessage();
- $this->mySQLlastErrNum = $ex->getCode();
- }
- }
-
- }
- else
- {
- $sQryRes = is_null($rli) ? @mysql_query($query,$this->mySQLaccess) : @mysql_query($query, $rli);
- $this->mySQLlastErrNum = mysql_errno();
- $this->mySQLlastErrText = mysql_error();
- }
-
$e = microtime();
e107::getSingleton('e107_traffic')->Bump('db_Query', $b, $e);
@@ -580,17 +429,9 @@ class e_db_mysql implements e_db
if (!is_array($query) && (strpos($query,'EXPLAIN') !==0) && (strpos($query,'SQL_CALC_FOUND_ROWS') !== false) && (strpos($query,'SELECT') !== false))
{
- if($this->pdo)
- {
- $rc = $this->mySQLaccess->query('SELECT FOUND_ROWS();')->fetch(PDO::FETCH_COLUMN);
- $this->total_results = intval($rc);
- }
- else /* @XXX Subject of Removal. */
- {
- $fr = mysql_query('SELECT FOUND_ROWS()', $this->mySQLaccess);
- $rc = mysql_fetch_array($fr);
- $this->total_results = (int) $rc['FOUND_ROWS()'];
- }
+ $fr = mysql_query('SELECT FOUND_ROWS()', $this->mySQLaccess);
+ $rc = mysql_fetch_array($fr);
+ $this->total_results = (int)$rc['FOUND_ROWS()'];
}
@@ -608,35 +449,7 @@ class e_db_mysql implements e_db
if(is_object($db_debug))
{
$buglink = is_null($rli) ? $this->mySQLaccess : $rli;
-
- if($this->pdo == true)
- {
- if(is_array($query))
- {
- $query = "PREPARE: ".$query['PREPARE']."
BIND:".print_a($query['BIND'],true); // ,true);
- }
-
- if(isset($ex) && is_object($ex))
- {
- $query = $ex->getMessage();
- $query .= print_a($ex->getTrace(),true);
- }
- }
-
- if($this->pdo == true && $buglink instanceof PDO)
- {
-
- $db_debug->Mark_Query($query, 'PDO', $sQryRes, $aTrace, $mytime, $pTable);
- }
- else
- {
-
- $db_debug->Mark_Query($query, $buglink, $sQryRes, $aTrace, $mytime, $pTable);
- }
- }
- else
- {
- // echo "what happened to db_debug??!!
";
+ $db_debug->Mark_Query($query, $buglink, $sQryRes, $aTrace, $mytime, $pTable);
}
}
@@ -694,7 +507,7 @@ class e_db_mysql implements e_db
{
$ret = array();
if(!$multi) return $this->fetch();
-
+
while($row = $this->fetch())
{
if(null !== $indexField) $ret[$row[$indexField]] = $row;
@@ -702,7 +515,7 @@ class e_db_mysql implements e_db
}
return $ret;
}
-
+
// detect mode
$mode = 'one';
if($table && !$where && is_bool($fields))
@@ -720,7 +533,7 @@ class e_db_mysql implements e_db
{
$mode = 'multi';
}
-
+
// detect query type
$select = true;
$noWhere = false;
@@ -736,9 +549,9 @@ class e_db_mysql implements e_db
// FIXME - move auto detect to select()?
$noWhere = true;
}
-
+
// execute & fetch
- switch ($mode)
+ switch ($mode)
{
case 'single':
if($select && !$this->select($table, $fields, $where, $noWhere, $debug))
@@ -752,7 +565,7 @@ class e_db_mysql implements e_db
$rows = $this->fetch();
return array_shift($rows);
break;
-
+
case 'one':
if($select && !$this->select($table, $fields, $where, $noWhere, $debug))
{
@@ -764,7 +577,7 @@ class e_db_mysql implements e_db
}
return $this->fetch();
break;
-
+
case 'multi':
if($select && !$this->select($table, $fields, $where, $noWhere, $debug))
{
@@ -782,7 +595,7 @@ class e_db_mysql implements e_db
}
return $ret;
break;
-
+
}
}
@@ -807,7 +620,7 @@ class e_db_mysql implements e_db
$table = $this->db_IsLang($table);
$this->mySQLcurTable = $table;
-
+
if ($arg != '' && ($noWhere === false || $noWhere === 'default')) // 'default' for BC.
{
if ($this->mySQLresult = $this->db_Query('SELECT '.$fields.' FROM '.$this->mySQLPrefix.$table.' WHERE '.$arg, NULL, 'db_Select', $debug, $log_type, $log_remark))
@@ -851,7 +664,7 @@ class e_db_mysql implements e_db
/**
* select() alias
- *
+ *
* @deprecated
*/
public function db_Select($table, $fields = '*', $arg = '', $mode = 'default', $debug = FALSE, $log_type = '', $log_remark = '')
@@ -944,13 +757,10 @@ class e_db_mysql implements e_db
$fieldTypes = $this->_getTypes($arg);
$keyList= '`'.implode('`,`', array_keys($arg['data'])).'`';
$tmp = array();
- $bind = array();
foreach($arg['data'] as $fk => $fv)
{
- $tmp[] = ($this->pdo == true) ? ':'.$fk : $this->_getFieldValue($fk, $fv, $fieldTypes);
- $fieldType = isset($fieldTypes[$fk]) ? $fieldTypes[$fk] : null;
- $bind[$fk] = array('value'=>$this->_getPDOValue($fieldType,$fv), 'type'=> $this->_getPDOType($fieldType,$this->_getPDOValue($fieldType,$fv)));
+ $tmp[] = $this->_getFieldValue($fk, $fv, $fieldTypes);
}
$valList= implode(', ', $tmp);
@@ -975,17 +785,6 @@ class e_db_mysql implements e_db
{
$query = "REPLACE INTO ".$this->mySQLPrefix."{$table} ({$keyList}) VALUES ({$valList})";
}
-
-
- if($this->pdo == true)
- {
- $query = array(
- 'PREPARE' => $query,
- 'BIND' => $bind,
- );
- }
-
-
}
else
{
@@ -1000,10 +799,7 @@ class e_db_mysql implements e_db
{
$result = false; // ie. there was an error.
- if($this->pdo !== true)
- {
- $this->mySQLresult = mysql_affected_rows($this->mySQLaccess);
- }
+ $this->mySQLresult = mysql_affected_rows($this->mySQLaccess);
if($this->mySQLresult === 1 ) // insert.
{
@@ -1030,15 +826,13 @@ class e_db_mysql implements e_db
{
if(true === $REPLACE)
{
- $tmp = ($this->pdo) ? $this->mySQLresult : mysql_affected_rows($this->mySQLaccess);
+ $tmp = mysql_affected_rows($this->mySQLaccess);
$this->dbError('db_Replace');
// $tmp == -1 (error), $tmp == 0 (not modified), $tmp == 1 (added), greater (replaced)
if ($tmp == -1) { return false; } // mysql_affected_rows error
return $tmp;
}
- // $tmp = ($this->pdo) ? $this->mySQLaccess->lastInsertId() : mysql_insert_id($this->mySQLaccess);
-
$tmp = $this->lastInsertId();
$this->dbError('db_Insert');
@@ -1050,11 +844,11 @@ class e_db_mysql implements e_db
return FALSE;
}
}
-
+
public function lastInsertId()
{
- $tmp = ($this->pdo) ? (int) $this->mySQLaccess->lastInsertId() : mysql_insert_id($this->mySQLaccess);
+ $tmp = mysql_insert_id($this->mySQLaccess);
return ($tmp) ? $tmp : true; // return true even if table doesn't have auto-increment.
}
@@ -1068,38 +862,24 @@ class e_db_mysql implements e_db
return $this->total_results;
}
-
+ /**
+ * @param resource $result
+ * @return false|int
+ */
public function rowCount($result=null)
{
-
- if($this->pdo)
+ if (!is_resource($result))
{
- if(!$this->mySQLresult)
- {
- return -1;
- }
-
+ $result = $this->mySQLresult;
}
-
- /** @var PDOStatement $resource */
- $resource = $this->mySQLresult;
- if ($this->pdo)
+ if (is_resource($result))
{
- $this->mySQLrows = $resource->rowCount();
- }
- elseif (is_resource($this->mySQLresult))
- {
- $this->mySQLrows = mysql_num_rows($this->mySQLresult);
+ $this->mySQLrows = mysql_num_rows($result);
}
$this->dbError('db_Rows');
return $this->mySQLrows;
}
-
-
-
-
-
/**
* insert() alias
* @deprecated
@@ -1128,7 +908,7 @@ class e_db_mysql implements e_db
$arg['_REPLACE'] = TRUE;
return $this->insert($table, $arg, $debug, $log_type, $log_remark);
}
-
+
/**
* replace() alias
* @deprecated
@@ -1141,10 +921,8 @@ class e_db_mysql implements e_db
private function _prepareUpdateArg($tableName, $arg)
{
- $this->pdoBind = array();
if (is_array($arg)) // Remove the need for a separate db_UpdateArray() function.
{
-
if(!isset($arg['_FIELD_TYPES']) && !isset($arg['data']))
{
//Convert data if not using 'new' format
@@ -1172,23 +950,11 @@ class e_db_mysql implements e_db
$new_data = '';
- //$this->pdoBind = array(); // moved up to the beginning of the method to make sure it is initialized properly
foreach ($arg['data'] as $fn => $fv)
{
$new_data .= ($new_data ? ', ' : '');
- $ftype = isset($fieldTypes[$fn]) ? $fieldTypes[$fn] : 'str';
- $new_data .= ($this->pdo == true && $ftype !='cmd') ? "`{$fn}`= :". $fn : "`{$fn}`=".$this->_getFieldValue($fn, $fv, $fieldTypes);
-
- if($fv === '_NULL_')
- {
- $ftype = 'null';
- }
-
- if($ftype != 'cmd')
- {
- $this->pdoBind[$fn] = array('value'=>$this->_getPDOValue($ftype,$fv), 'type'=> $this->_getPDOType($ftype,$this->_getPDOValue($ftype,$fv)));
- }
+ $new_data .= "`{$fn}`=".$this->_getFieldValue($fn, $fv, $fieldTypes);
}
$arg = $new_data .(isset($arg['WHERE']) ? ' WHERE '. $arg['WHERE'] : '');
@@ -1229,33 +995,12 @@ class e_db_mysql implements e_db
$query = 'UPDATE '.$this->mySQLPrefix.$table.' SET '.$arg;
- if($this->pdo == true && !empty($this->pdoBind))
- {
- $query = array(
- 'PREPARE' => $query,
- 'BIND' => $this->pdoBind,
- );
- }
-
$result = $this->mySQLresult = $this->db_Query($query, NULL, 'db_Update', $debug, $log_type, $log_remark);
if ($result !==false)
{
+ $result = mysql_affected_rows($this->mySQLaccess);
- if($this->pdo == true)
- {
- if(is_object($result))
- {
- // make sure to return the number of records affected, instead of an object
- $result = $this->rowCount();
- }
- }
- else
- {
- $result = mysql_affected_rows($this->mySQLaccess);
- }
-
- // $result = ($this->pdo) ? $result : mysql_affected_rows($this->mySQLaccess);
$this->dbError('db_Update');
if ($result === -1) { return false; } // Error return from mysql_affected_rows
return $result;
@@ -1317,7 +1062,7 @@ class e_db_mysql implements e_db
case 'cmd':
return $fieldValue;
break;
-
+
case 'safestr':
return "'{$fieldValue}'";
break;
@@ -1356,7 +1101,7 @@ class e_db_mysql implements e_db
if($fieldValue == '') { return "''"; }
return "'".e107::getParser()->toDB($fieldValue)."'";
break;
-
+
case 'escape':
default:
return "'".$this->escape($fieldValue, false)."'";
@@ -1364,114 +1109,6 @@ class e_db_mysql implements e_db
}
}
-
- /**
- * Return a value for use in PDO bindValue() - based on field-type.
- * @param $type
- * @param $fieldValue
- * @return int|string
- */
- private function _getPDOValue($type, $fieldValue)
- {
-
-
- if(is_string($fieldValue) && ($fieldValue === '_NULL_'))
- {
- $type = 'null';
- }
-
- switch($type)
- {
- case "int":
- case "integer":
- return (int) $fieldValue;
- break;
-
-
-
- case 'float':
- // fix - convert localized float numbers
- // $larr = localeconv();
- // $search = array($larr['decimal_point'], $larr['mon_decimal_point'], $larr['thousands_sep'], $larr['mon_thousands_sep'], $larr['currency_symbol'], $larr['int_curr_symbol']);
- // $replace = array('.', '.', '', '', '', '');
-
- // return str_replace($search, $replace, floatval($fieldValue));
- return e107::getParser()->toNumber($fieldValue);
- break;
-
- case 'null':
- return (
- is_string($fieldValue) && (
- ($fieldValue !== '_NULL_') && ($fieldValue !== '')
- )
- ) ? $fieldValue : null;
- break;
-
- case 'array':
- if(is_array($fieldValue))
- {
- return e107::serialize($fieldValue);
- }
- return $fieldValue;
- break;
-
- case 'todb': // using as default causes serious BC issues.
- if($fieldValue == '') { return ''; }
- return e107::getParser()->toDB($fieldValue);
- break;
-
- case 'cmd':
- case 'safestr':
- case 'str':
- case 'string':
- case 'escape':
- default:
-
- return $fieldValue;
- break;
-
- }
-
-
- }
-
-
- /**
- * Convert FIELD_TYPE to PDO compatible Field-Type
- * @param $type
- * @return int
- */
- private function _getPDOType($type, $value = null)
- {
- switch($type)
- {
- case "int":
- case "integer":
- return PDO::PARAM_INT;
- break;
-
- case 'null':
- return ($value === null) ? PDO::PARAM_NULL : PDO::PARAM_STR;
- break;
-
- case 'cmd':
- case 'safestr':
- case 'str':
- case 'string':
- case 'escape':
- case 'array':
- case 'todb':
- case 'float':
- return PDO::PARAM_STR;
- break;
-
- }
-
- // e107::getMessage()->addDebug("MySQL Missing Field-Type: ".$type);
- return PDO::PARAM_STR;
- }
-
-
/**
* @DEPRECATED
Similar to db_Update(), but splits the variables and the 'WHERE' clause.
@@ -1501,7 +1138,7 @@ class e_db_mysql implements e_db
}
if ($result = $this->mySQLresult = $this->db_Query('UPDATE '.$this->mySQLPrefix.$table.' SET '.$new_data.$vars.' '.$arg, NULL, 'db_UpdateArray', $debug, $log_type, $log_remark))
{
- $result = ($this->pdo) ? $this->mySQLresult->rowCount() : mysql_affected_rows($this->mySQLaccess);
+ $result = mysql_affected_rows($this->mySQLaccess);
if ($result == -1) return FALSE; // Error return from mysql_affected_rows
return $result;
}
@@ -1538,59 +1175,33 @@ class e_db_mysql implements e_db
*/
function fetch($type = null)
{
-
if(defined('MYSQL_ASSOC'))
{
switch ($type)
{
case 'both':
case 3: // MYSQL_BOTH:
- $type = ($this->pdo) ? PDO::FETCH_BOTH: MYSQL_BOTH; // 3
+ $type = MYSQL_BOTH; // 3
break;
case 'num':
case 2; // MYSQL_NUM: // 2
- $type = ($this->pdo) ? PDO::FETCH_NUM : MYSQL_NUM;
+ $type = MYSQL_NUM;
break;
default:
case 'assoc':
case 1; //: // 1
- $type = ($this->pdo) ? PDO::FETCH_ASSOC : MYSQL_ASSOC;
+ $type = MYSQL_ASSOC;
break;
}
}
- else
- {
-
- if($this->pdo) // convert type to PDO.
- {
- switch ($type)
- {
- case 'both': // 3
- $type = PDO::FETCH_BOTH;
- break;
-
- case 'num': // 2
- $type = PDO::FETCH_NUM;
- break;
-
- case 'assoc': // 1
- default:
- $type = PDO::FETCH_ASSOC;
- break;
- }
- }
- }
-
$b = microtime();
if($this->mySQLresult)
{
- /** @var PDOStatement $resource */
- $resource = $this->mySQLresult;
- $row = ($this->pdo) ? $resource->fetch($type) : @mysql_fetch_array($this->mySQLresult,$type);
+ $row = @mysql_fetch_array($this->mySQLresult, $type);
e107::getSingleton('e107_traffic')->Bump('db_Fetch', $b);
if ($row)
{
@@ -1601,7 +1212,7 @@ class e_db_mysql implements e_db
$this->dbError('db_Fetch');
return FALSE; // Failure
}
-
+
/**
* fetch() alias
* @deprecated
@@ -1635,7 +1246,7 @@ class e_db_mysql implements e_db
$query=$table;
if ($this->mySQLresult = $this->db_Query($query, NULL, 'db_Count', $debug, $log_type, $log_remark))
{
- $rows = $this->mySQLrows = ($this->pdo) ? $this->mySQLresult->fetch(PDO::FETCH_ASSOC) : @mysql_fetch_array($this->mySQLresult);
+ $rows = $this->mySQLrows = @mysql_fetch_array($this->mySQLresult);
$this->dbError('db_Count');
return (int) $rows['COUNT(*)'];
}
@@ -1655,7 +1266,7 @@ class e_db_mysql implements e_db
$query='SELECT COUNT'.$fields.' FROM '.$this->mySQLPrefix.$table.' '.$arg;
if ($this->mySQLresult = $this->db_Query($query, NULL, 'db_Count', $debug, $log_type, $log_remark))
{
- $rows = $this->mySQLrows = ($this->pdo) ? $this->mySQLresult->fetch(PDO::FETCH_NUM) : @mysql_fetch_array($this->mySQLresult);
+ $rows = $this->mySQLrows = @mysql_fetch_array($this->mySQLresult);
$this->dbError('db_Count');
return (int) $rows[0];
}
@@ -1730,7 +1341,7 @@ class e_db_mysql implements e_db
if ($result = $this->mySQLresult = $this->db_Query('DELETE FROM '.$this->mySQLPrefix.$table, NULL, 'db_Delete', $debug, $log_type, $log_remark))
{
// return the number of records deleted instead of an object
- $this->mySQLrows = ($this->pdo) ? $this->mySQLresult->rowCount() : mysql_affected_rows($this->mySQLaccess);
+ $this->mySQLrows = mysql_affected_rows($this->mySQLaccess);
$this->dbError('db_Delete');
return $this->mySQLrows;
}
@@ -1744,7 +1355,7 @@ class e_db_mysql implements e_db
{
if ($result = $this->mySQLresult = $this->db_Query('DELETE FROM '.$this->mySQLPrefix.$table.' WHERE '.$arg, NULL, 'db_Delete', $debug, $log_type, $log_remark))
{
- $this->mySQLrows = ($this->pdo) ? $this->mySQLresult->rowCount() : mysql_affected_rows($this->mySQLaccess);
+ $this->mySQLrows = mysql_affected_rows($this->mySQLaccess);
$this->dbError('db_Delete');
return $this->mySQLrows;
}
@@ -1773,7 +1384,7 @@ class e_db_mysql implements e_db
function db_Rows()
{
return $this->rowCount();
-
+
}
@@ -1829,9 +1440,7 @@ class e_db_mysql implements e_db
{ // Successful query which may return a row count (because it operated on a number of rows without returning a result set)
if(preg_match('#^(DELETE|INSERT|REPLACE|UPDATE)#',$query, $matches))
{ // Need to check mysql_affected_rows() - to return number of rows actually updated
- /** @var PDOStatement $resource */
- $resource = $this->mySQLresult;
- $tmp = ($this->pdo) ? $resource->rowCount() : mysql_affected_rows($this->mySQLaccess);
+ $tmp = mysql_affected_rows($this->mySQLaccess);
$this->dbError('db_Select_gen');
return $tmp;
}
@@ -1984,16 +1593,16 @@ class e_db_mysql implements e_db
}
- /**
- * Deprecated alias of the rows() function below.
+ /**
+ * Deprecated alias of the rows() function below.
*/
function db_getList($fields = 'ALL', $amount = FALSE, $maximum = FALSE, $ordermode=FALSE)
{
return $this->rows($fields, $amount, $maximum, $ordermode);
}
-
-
-
+
+
+
/**
* @return array
* @param string fields to retrieve
@@ -2274,9 +1883,9 @@ class e_db_mysql implements e_db
{
return false; // Error return
}
-
+
$ret = array();
-
+
if ($this->rowCount() > 0)
{
while ($row = $this->fetch())
@@ -2298,27 +1907,14 @@ class e_db_mysql implements e_db
function db_Field($table,$fieldid="",$key="", $retinfo = FALSE)
{
- return $this->field($table,$fieldid,$key, $retinfo);
+ return $this->field($table,$fieldid,$key, $retinfo);
}
-
function columnCount()
{
- if($this->pdo)
- {
- /** @var PDOStatement $resource */
- $resource = $this->mySQLresult;
- return $resource->columnCount();
- }
- else
- {
- return mysql_num_fields($this->mySQLresult);
- }
-
+ return mysql_num_fields($this->mySQLresult);
}
-
-
/**
* Determines if a plugin field (and key) exist. OR if fieldid is numeric - return the field name in that position.
*
@@ -2444,19 +2040,12 @@ class e_db_mysql implements e_db
*/
function escape($data, $strip = true)
{
-
if ($strip)
{
$data = strip_if_magic($data);
}
$this->provide_mySQLaccess();
-
- if($this->pdo)
- {
- return $data;
- // return $this->mySQLaccess->quote($data);
- }
return mysql_real_escape_string($data,$this->mySQLaccess);
}
@@ -2641,7 +2230,7 @@ class e_db_mysql implements e_db
{
$this->mySQLtableList = $this->db_mySQLtableList();
}
-
+
if($mode == 'nologs')
{
$ret = array();
@@ -2649,14 +2238,14 @@ class e_db_mysql implements e_db
{
if(substr($table,-4) != '_log' && $table != 'download_requests')
{
- $ret[] = $table;
- }
-
+ $ret[] = $table;
+ }
+
}
-
+
return $ret;
}
-
+
if($mode == 'all')
{
@@ -2687,7 +2276,7 @@ class e_db_mysql implements e_db
/**
- * Duplicate a Table Row in a table.
+ * Duplicate a Table Row in a table.
*/
function db_CopyRow($table,$fields = '*', $args='')
{
@@ -2695,10 +2284,10 @@ class e_db_mysql implements e_db
{
return false;
}
-
+
if($fields === '*')
{
- $fields = $this->db_FieldList($table);
+ $fields = $this->db_FieldList($table);
unset($fields[0]); // Remove primary_id.
$fieldList = implode(",",$fields);
}
@@ -2706,7 +2295,7 @@ class e_db_mysql implements e_db
{
$fieldList = $fields;
}
-
+
if(empty($fields))
{
$this->mysqlLastErrText = "copyRow \$fields list was empty";
@@ -2718,8 +2307,8 @@ class e_db_mysql implements e_db
return ($id && $lastInsertId) ? $lastInsertId : false;
}
-
-
+
+
function db_CopyTable($oldtable, $newtable, $drop = FALSE, $data = FALSE)
{
@@ -2771,149 +2360,18 @@ class e_db_mysql implements e_db
/**
- * Dump MySQL Table(s) to a file in the Backup folder.
+ * Dump MySQL Table(s) to a file in the Backup folder.
* @param $table string - name without the prefix or '*' for all
- * @param $file string - optional file name. or leave blank to generate.
- * @param $options - additional preferences.
+ * @param $file string - optional file name. or leave blank to generate.
+ * @param $options - additional preferences.
* @return string|bool backup file path.
*/
function backup($table='*', $file='', $options=null)
{
-
- if($this->pdo === false)
- {
- $this->mysqlLastErrText = "PDO is required to use the mysql backup() method";
- return false;
- }
-
- // $dbtable = $this->mySQLdefaultdb;
- $fileName = ($table =='*') ? str_replace(" ","_",SITENAME) : $table;
- $fileName = preg_replace('/[^\w]/i',"",$fileName);
-
- $backupFile = ($file) ? e_BACKUP.$file : e_BACKUP.strtolower($fileName)."_".$this->mySQLPrefix.date("Y-m-d-H-i-s").".sql";
-
- if($table === '*')
- {
- $nolog = vartrue($options['nologs']) ? 'nologs' : 'all';
- $tableList = $this->tables($nolog);
- }
- else
- {
- $tableList = explode(",",$table);
- }
-
- if(!empty($options['gzip']))
- {
- $backupFile .= '.gz';
- }
-
-
- include_once(dirname(__FILE__) . '/Ifsnop/Mysqldump/Mysqldump.php');
-
- $config = e107::getMySQLConfig();
-
- $dumpSettings = array(
- 'compress' => !empty($options['gzip']) ? Ifsnop\Mysqldump\Mysqldump::GZIP : Ifsnop\Mysqldump\Mysqldump::NONE,
- 'include-tables' => array(),
- 'no-data' => false,
- 'add-drop-table' => !empty($options['droptable']) ? true : false,
- 'single-transaction' => true,
- 'lock-tables' => true,
- 'add-locks' => true,
- 'extended-insert' => true,
- 'disable-foreign-keys-check' => true,
- 'skip-triggers' => false,
- 'add-drop-trigger' => true,
- 'databases' => false,
- 'add-drop-database' => false,
- 'hex-blob' => true,
- 'reset-auto-increment' => false,
- );
-
- foreach($tableList as $tab)
- {
- $dumpSettings['include-tables'][] = $config['mySQLprefix'].trim($tab);
- }
-
-
- try {
- $dump = new Ifsnop\Mysqldump\Mysqldump('mysql:host='.$config['mySQLserver'].';dbname='.$config['mySQLdefaultdb'], $config['mySQLuser'], $config['mySQLpassword'], $dumpSettings);
- $dump->start($backupFile);
- return $backupFile;
- }
- catch (\Exception $e)
- {
- $this->mysqlLastErrText = 'mysqldump-php error: ' .$e->getMessage();
- return false;
- }
-
-
-/*
-
-
- $header = "-- e107 Database Backup File \n";
- $header .= "-- Host: ".$_SERVER['SERVER_NAME']."\n";
- $header .= "-- Generation Time: ".date('r')."\n";
- $header .= "-- Encoding: UTF-8\n\n\n";
-
- file_put_contents($backupFile,$header, FILE_APPEND);
-
- foreach ($tableList as $table)
- {
- unset($text);
- $text = "";
- $text .= vartrue($options['droptable']) ? "DROP TABLE IF EXISTS `".$this->mySQLPrefix.$table."`;\n" : "";
- $this->gen("SHOW CREATE TABLE `".$this->mySQLPrefix.$table."`");
- $row2 = $this->fetch();
- $text .= $row2['Create Table'];
- $text .= ";\n\n";
-
- file_put_contents($backupFile,$text,FILE_APPEND);
- // echo $text;
- // ob_end_clean(); // prevents memory exhaustian on large databases but breaks layout. .
-
- $count = $this->gen("SELECT * FROM `#".$table."`");
- $data_array = "";
-
- //TODO After so many rows (50,000?), make a new files to avoid overly large inserts.
- while($row = $this->fetch())
- {
- $fields = array_keys($row);
- $text = "\nINSERT INTO `".$this->mySQLPrefix.$table."` (`".implode("` ,`",$fields)."`) VALUES \n";
- file_put_contents($backupFile,$text,FILE_APPEND);
-
- $d = array();
- foreach($fields as $val)
- {
- $d[] = is_numeric($row[$val]) ? $row[$val] : "'".$this->escape($row[$val])."'";
- }
-
- $data_array = "(".implode(", ",$d).");\n";
- file_put_contents($backupFile, $data_array, FILE_APPEND); // Do this here to save memory.
-
- }
-
- $text = "\n\n\n";
- file_put_contents($backupFile, $text, FILE_APPEND);
- unset($fields);
-
- }
-
- return $backupFile;
- // file_put_contents('memory.log', 'memory used in line ' . __LINE__ . ' is: ' . memory_get_usage() . PHP_EOL, FILE_APPEND);
- */
+ $this->mysqlLastErrText = "PDO is required to use the mysql backup() method";
+ return false;
}
-
-
-
-
-
-
-
-
-
-
/**
* @return string relating to error (empty string if no error)
* @param string $from
@@ -2922,23 +2380,6 @@ class e_db_mysql implements e_db
*/
function dbError($from)
{
-
-// $this->mySQLaccess->getMessage();
-
- if($this->pdo)
- {
- $this->mySQLerror = true;
-
- if($this->mySQLlastErrNum === 0)
- {
- return null;
- }
-
- return $from." :: ".$this->mySQLlastErrText;
- }
-
-
-
$this->mySQLlastErrNum = mysql_errno();
$this->mySQLlastErrText = '';
if ($this->mySQLlastErrNum == 0)
@@ -3011,7 +2452,7 @@ class e_db_mysql implements e_db
{
if ( ! $debug)
{
- ($this->pdo) ? $this->db_Query("SET NAMES `$charset`") : @mysql_query("SET NAMES `$charset`");
+ @mysql_query("SET NAMES `$charset`");
}
else
{
@@ -3202,10 +2643,10 @@ class e_db_mysql implements e_db
$outDefs['_FIELD_TYPES'][$v['name']] = 'escape'; //XXX toDB() causes serious BC issues.
break;
}
-
+
// if($v['name'])
-
-
+
+
if (isset($v['nulltype']) && !isset($v['default']))
{
$outDefs['_NOTNULL'][$v['name']] = '';
@@ -3227,7 +2668,7 @@ class e_db_mysql implements e_db
if (FALSE === file_put_contents(e_CACHE_DB.$tableName.'.php', $toSave))
{ // Could do something with error - but mustn't return FALSE - would trigger auto-generated structure
$mes = e107::getMessage();
- $mes->addDebug("Error writing file: ".e_CACHE_DB.$tableName.'.php'); //Fix for during v1.x -> 2.x upgrade.
+ $mes->addDebug("Error writing file: ".e_CACHE_DB.$tableName.'.php'); //Fix for during v1.x -> 2.x upgrade.
// echo "Error writing file: ".e_CACHE_DB.$tableName.'.php'.'
';
}
@@ -3254,7 +2695,7 @@ class e_db_mysql implements e_db
/**
* @deprecated 2.1.9 Used only to provide $mySQLaccess to other instances of e_db_mysql scattered around
- * @return PDO
+ * @return resource
*/
public function get_mySQLaccess()
{