ecshop适应在PHP7的修改方法解决报错的实现

发布时间:2022-04-30 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了ecshop适应在PHP7的修改方法解决报错的实现脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。

ecshop这个系统,到目前也没见怎么推出新版本,如果是新项目,不太建议使用它。不过,因为我一直以来都在使用中,所以不得不更改让其适应PHP新版本。现在PHP 7已经出发行版了,所以更改来继续使用吧。具体的更改有以下方面:

(1)将MysqL扩展的使用替换掉,改为使用MysqLi或pdo:

PHP5.5开始MysqL扩展将废弃了。

具体更改的文件在于includes/cls_MysqL.PHP。这是个不小的工程,文件代码太长……

class cls_MySQL
{
VAR $link_id = NULL;

var $settings = array();

var $queryCount = 0;
var $queryTime = '';
var $queryLOG = array();

var $max_cache_time = 300; // 最大的缓存时间,以秒为单位

var $cache_data_dir = 'temp/query_caches/';
var $root_path = '';

var $error_message = array();
var $platform = '';
var $version = '';
var $dbhash = '';
var $starttime = 0;
var $timeline = 0;
var $timezone = 0;
// 事务指令数
PRotected $transTimes = 0;

var $mySQL_config_cache_file_time = 0;

var $mysql_disable_cache_tables = array(); // 不允许被缓存的表,遇到将不会进行缓存

function _construct($dbhost,$dbuser,$dbpw,$dbname = '',$charset = 'gbk',$pconnect = 0,$quiet = 0)
{
$this->cls
MysqL($dbhost,$dbname,$charset,$pconnect,$quiet);
}

function cls_MysqL($dbhost,$quiet = 0)
{
if (defined('EC_CHARSET'))
{
$charset = strtolower(str_replace('-','',EC_CHARSET));
}

if (defined('ROOT_PATH') && !$this->root_path)
{
  $this->root_path = ROOT_PATH;
}

if ($quiet)
{
  $this->connect($dbhost,$quiet);
}
else
{
  $this->settings = array(
              'dbhost'  => $dbhost,'dbuser'  => $dbuser,'dbpw'   => $dbpw,'dbname'  => $dbname,'charset' => $charset,'pconnect' => $pconnect
              );
}

}

function connect($dbhost,$charset = 'utf8',$quiet = 0)
{
if ($pconnect)
{
$this->link_id = new MysqLi('p:'.$dbhost,$dbpw);
if ($this->link_id->connect_error)
{
if (!$quiet)
{
$this->ErrorMsg("Can't pConnect MysqL Server($dbhost)!");
}

    return false;
  }
}
else
{
  $this->link_id = new <a href="https://www.js-code.COM/tag/MysqL/" target="_blank" class="keywords">;mysqL</a>i($dbhost,$dbpw);

  if ($this->link_id->connect_error)
  {
    if (!$quiet)
    {
      $this->ErrorMsg("Can't Connect <a href="https://www.js-code.com/tag/MysqL/" target="_blank" class="keywords">MysqL</a> Server($dbhost)!");
    }

    return false;
  }
}

$this->dbhash = md5($this->root_path . $dbhost . $dbuser . $dbpw . $dbname);
$this->version = $this->link_id->server_version;

/* 对字符集进行初始化 */
$this->link_id->set_charset($charset);

$this->link_id->query("SET <a href="https://www.js-code.com/tag/sqlmode/" target="_blank" class="keywords">sql_mode</a>=''");
$<a href="https://www.js-code.com/tag/sql/" target="_blank" class="keywords">sql</a>cache_con<a href="https://www.js-code.com/tag/fig/" target="_blank" class="keywords">fig</a>_file = $this->root_path . $this->cache_<a href="https://www.js-code.com/tag/datadir/" target="_blank" class="keywords">data_dir</a> . '<a href="https://www.js-code.com/tag/sql/" target="_blank" class="keywords">sql</a>cache_con<a href="https://www.js-code.com/tag/fig/" target="_blank" class="keywords">fig</a>_file_' . $this->dbhash . '.<a href="https://www.js-code.com/tag/PHP/" target="_blank" class="keywords">PHP</a>';

@include($<a href="https://www.js-code.com/tag/sql/" target="_blank" class="keywords">sql</a>cache_con<a href="https://www.js-code.com/tag/fig/" target="_blank" class="keywords">fig</a>_file);

$this->starttime = time();

if ($this->max_cache_time &amp;& $this->starttime > $this-><a href="https://www.js-code.com/tag/MysqL/" target="_blank" class="keywords">MysqL</a>_con<a href="https://www.js-code.com/tag/fig/" target="_blank" class="keywords">fig</a>_cache_file_time + $this->max_cache_time)
{
  if ($dbhost != '.')
  {
    $result = $this->link_id->query("SHOW VARIABLES LIKE 'basedir'");
    $row = $result->fetch_array(<a href="https://www.js-code.com/tag/MysqL/" target="_blank" class="keywords">MysqL</a>I_ASSOC);
    $result->free();
    if (!empty($row['Value']{1}) && $row['Value']{1} == ':' && !empty($row['Value']{2}) && $row['Value']{2} == "/")
    {
      $this->platform = 'WINDOWS';
    }
    else
    {
      $this->platform = 'OTHER';
    }
  }
  else
  {
    $this->platform = 'WINDOWS';
  }

  if ($this->platform == 'OTHER' &&
    ($dbhost != '.' && strtolower($dbhost) != 'localhost:3306' && $dbhost != '127.0.0.1:3306') ||
    date_default_timezone_get() == 'UTC')
  {
    $result = $this->link_id->query("SELECT UNIX_TIMESTAMP() AS timeline,UNIX_TIMESTAMP('" . date('Y-m-d H:i:s',$this->starttime) . "') AS timezone");
    $row = $result->fetch_array(<a href="https://www.js-code.com/tag/MysqL/" target="_blank" class="keywords">MysqL</a>I_ASSOC);
    $result->free();
    if ($dbhost != '.' && strtolower($dbhost) != 'localhost:3306' && $dbhost != '127.0.0.1:3306')
    {
      $this->timeline = $this->starttime - $row['timeline'];
    }
    if (date_default_timezone_get() == 'UTC')
    {
      $this->timezone = $this->starttime - $row['timezone'];
    }
  }

  $content = '<' . "?php\r\n" .
        '$this-><a href="https://www.js-code.com/tag/MysqL/" target="_blank" class="keywords">MysqL</a>_con<a href="https://www.js-code.com/tag/fig/" target="_blank" class="keywords">fig</a>_cache_file_time = ' . $this->starttime . ";\r\n" .
        '$this->timeline = ' . $this->timeline . ";\r\n" .
        '$this->timezone = ' . $this->timezone . ";\r\n" .
        '$this->platform = ' . "'" . $this->platform . "';\r\n?" . '>';

  @file_put_contents($<a href="https://www.js-code.com/tag/sql/" target="_blank" class="keywords">sql</a>cache_con<a href="https://www.js-code.com/tag/fig/" target="_blank" class="keywords">fig</a>_file,$content);
}

/* 选择<a href="https://www.js-code.com/tag/shujuku/" target="_blank" class="keywords">数据库</a> */
if ($dbname)
{

  if ($this->link_id->select_db($dbname) === false )
  {
    if (!$quiet)
    {
      $this->ErrorMsg("Can't select <a href="https://www.js-code.com/tag/MysqL/" target="_blank" class="keywords">MysqL</a> database($dbname)!");
    }

    return false;
  }
  else
  {
    return true;
  }
}
else
{
  return true;
}

}

function select_database($dbname)
{
return $this->link_id->select_db($dbname);
}

function set_MysqL_charset($charset)
{
if (in_array(strtolower($charset),array('gbk','Big5','utf-8','utf8')))
{
$charset = str_replace('-',$charset);
}
$this->link_id->set_charset($charset);
}

function fetch_array($query,$result_tyPE = MysqLI_ASSOC)
{
$row = $query->fetch_array($result_type);
$query->free();
return $row;
}

function query($sql,$type = '')
{
if ($this->link_id === NULL)
{
$this->connect($this->settings['dbhost'],$this->settings['dbuser'],$this->settings['dbpw'],$this->settings['dbname'],$this->settings['charset'],$this->settings['pconnect']);
$this->settings = array();
}

if ($this->queryCount++ <= 99)
{
  $this->queryLog[] = $<a href="https://www.js-code.com/tag/sql/" target="_blank" class="keywords">sql</a>;
}
if ($this->queryTime == '')
{
  if (<a href="https://www.js-code.com/tag/PHP/" target="_blank" class="keywords">PHP</a>_VERSION >= '5.0.0')
  {
    $this->queryTime = microtime(true);
  }
  else
  {
    $this->queryTime = microtime();
  }
}

/* 当当前的时间大于类初始化时<a href="https://www.js-code.com/tag/jiande/" target="_blank" class="keywords">间的</a>时候,<a href="https://www.js-code.com/tag/zidong/" target="_blank" class="keywords">自动</a>执行 ping 这个<a href="https://www.js-code.com/tag/zidong/" target="_blank" class="keywords">自动</a>重新连接操作 */
if (time() > $this->starttime + 1)
{
  $this->link_id->ping();
}

if (!($query = $this->link_id->query($<a href="https://www.js-code.com/tag/sql/" target="_blank" class="keywords">sql</a>)) && $type != 'SILENT')
{
  $this->error_message[]['message'] = '<a href="https://www.js-code.com/tag/MysqL/" target="_blank" class="keywords">MysqL</a> Query Error';
  $this->error_message[]['<a href="https://www.js-code.com/tag/sql/" target="_blank" class="keywords">sql</a>'] = $<a href="https://www.js-code.com/tag/sql/" target="_blank" class="keywords">sql</a>;
  $this->error_message[]['error'] = $this->link_id->error;
  $this->error_message[]['errno'] = $this->link_id->errno;

  $this->ErrorMsg();

  return false;
}

if (defined('DEBUG_MODE') && (DEBUG_MODE & 8) == 8)
{
  $logfilename = $this->root_path . <a href="https://www.js-code.com/tag/datadir/" target="_blank" class="keywords">data_dir</a> . '/<a href="https://www.js-code.com/tag/MysqL/" target="_blank" class="keywords">MysqL</a>_query_' . $this->dbhash . '_' . date('Y_m_d') . '.log';
  $str = $<a href="https://www.js-code.com/tag/sql/" target="_blank" class="keywords">sql</a> . "\n\n";

  if (<a href="https://www.js-code.com/tag/PHP/" target="_blank" class="keywords">PHP</a>_VERSION >= '5.0')
  {
    file_put_contents($logfilename,$str,FILE_APPEND);
  }
  else
  {
    $fp = @fopen($logfilename,'ab+');
    if ($fp)
    {
      fwrITe($fp,$str);
      fclose($fp);
    }
  }
}

return $query;

}

function affected_rows()
{
return $this->link_id->affected_rows;
}

function error()
{
return $this->link_id->error;
}

function errno()
{
return $this->link_id->errno;
}

function result($query,$row)
{
$query->data_seek($row);
$result = $query->fetch_row();
$query->free();
return $result;
}

function num_rows($query)
{
return $query->num_rows;
}

function num_fields($query)
{
return $this->link_id->field_count;
}

function free_result($query)
{
return $query->free();
}

function insert_id()
{
return $this->link_id->insert_id;
}

function fetchRow($query)
{
return $query->fetch_assoc();
}

function fetch_fields($query)
{
return $query->fetch_field();
}

function version()
{
return $this->version;
}

function ping()
{
return $this->link_id->ping();
}

function escape_string($unescaped_string)
{
return $this->link_id->real_escape_string($unescaped_string);
}

function close()
{
return $this->link_id->close();
}

function ErrorMsg($message = '',$sql = '')
{
if ($message)
{
echo "DTXB info: $message\n\n

";
//print('<a href="http://faq.comsenz.com/?type=mysql&dberrno=2003&dberror=Can%27t%20connect%20to%20MySQL%20server%20on" target="_blank">http://faq.comsenz.com/');
}
else
{
echo "MySQL server error report:";
print_r($this->error_message);
//echo "

<a href='http://faq.comsenz.com/?type=mysql&dberrno=" . $this->error_message[3]['errno'] . "&dberror=" . urlencode($this->error_message[2]['error']) . "' target='_blank'>http://faq.comsenz.com/";
}

exit;

}

/ 仿真 Adodb 函数 /
function selectLimit($sql,$num,$start = 0)
{
if ($start == 0)
{
$sql .= ' LIMIT ' . $num;
}
else
{
$sql .= ' LIMIT ' . $start . ',' . $num;
}

return $this->query($<a href="https://www.js-code.com/tag/sql/" target="_blank" class="keywords">sql</a>);

}

function getOne($sql,$limited = false)
{
if ($limited == true)
{
$sql = trim($sql . ' LIMIT 1');
}

$res = $this->query($<a href="https://www.js-code.com/tag/sql/" target="_blank" class="keywords">sql</a>);
if ($res !== false)
{
  $row = $res->fetch_row();
  $res->free();
  if ($row !== false)
  {
    return $row[0];
  }
  else
  {
    return '';
  }
}
else
{
  return false;
}

}

function getOneCached($sql,$cached = 'FILEFirst')
{
$sql = trim($sql . ' LIMIT 1');

$cachefirst = ($cached == 'FILEFIRST' || ($cached == '<a href="https://www.js-code.com/tag/MysqL/" target="_blank" class="keywords">MysqL</a>FIRST' && $this->platform != 'WINDOWS')) && $this->max_cache_time;
if (!$cachefirst)
{
  return $this->getOne($<a href="https://www.js-code.com/tag/sql/" target="_blank" class="keywords">sql</a>,true);
}
else
{
  $result = $this->get<a href="https://www.js-code.com/tag/sql/" target="_blank" class="keywords">sql</a>CacheData($<a href="https://www.js-code.com/tag/sql/" target="_blank" class="keywords">sql</a>,$cached);
  if (empty($result['Storecache']) == true)
  {
    return $result['data'];
  }
}

$arr = $this->getOne($<a href="https://www.js-code.com/tag/sql/" target="_blank" class="keywords">sql</a>,true);

if ($arr !== false && $cachefirst)
{
  $this->set<a href="https://www.js-code.com/tag/sql/" target="_blank" class="keywords">sql</a>CacheData($result,$arr);
}

return $arr;

}

function getAll($sql)
{
$res = $this->query($sql);
if ($res !== false)
{
$arr = $res->fetch_all(MysqLI_ASSOC);
$res->free();
return $arr;
}
else
{
return false;
}
}

function getAllCached($sql,$cached = 'FILEFIRST')
{
$cachefirst = ($cached == 'FILEFIRST' || ($cached == 'MysqLFIRST' && $this->platform != 'WINDOWS')) && $this->max_cache_time;
if (!$cachefirst)
{
return $this->getAll($sql);
}
else
{
$result = $this->getsqlCacheData

脚本宝典总结

以上是脚本宝典为你收集整理的ecshop适应在PHP7的修改方法解决报错的实现全部内容,希望文章能够帮你解决ecshop适应在PHP7的修改方法解决报错的实现所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: