您的位置:手机购彩平台 > 手机购彩平台-编程 > 所以更改来继续使用吧

所以更改来继续使用吧

2020-02-14 12:33

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

将mysql扩展的使用替换掉,改为使用mysqli或pdo:

从php5.5开始,mysql扩展将废弃了。

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

if ){ die;}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, $dbuser, $dbpw, $dbname, $charset, $pconnect, $quiet); } function cls_mysql($dbhost, $dbuser, $dbpw, $dbname = '', $charset = 'gbk', $pconnect = 0, $quiet = 0) { if ) { $charset = strtolower(str_replace; } if  && !$this->root_path) { $this->root_path = ROOT_PATH; } if  { $this->connect($dbhost, $dbuser, $dbpw, $dbname, $charset, $pconnect, $quiet); } else { $this->settings = array( 'dbhost' => $dbhost, 'dbuser' => $dbuser, 'dbpw' => $dbpw, 'dbname' => $dbname, 'charset' => $charset, 'pconnect' => $pconnect ); } } function connect($dbhost, $dbuser, $dbpw, $dbname = '', $charset = 'utf8', $pconnect = 0, $quiet = 0) { if  { $this->link_id = new mysqli('p:'.$dbhost, $dbuser, $dbpw); if ($this->link_id->connect_error) { if  { $this->ErrorMsg("Can't pConnect MySQL Server; } return false; } } else { $this->link_id = new mysqli($dbhost, $dbuser, $dbpw); if ($this->link_id->connect_error) { if  { $this->ErrorMsg("Can't Connect MySQL Server; } return false; } } $this->dbhash = md5($this->root_path . $dbhost . $dbuser . $dbpw . $dbname); $this->version = $this->link_id->server_version; /* 对字符集进行初始化 */ $this->link_id->set_charset; $this->link_id->query; $sqlcache_config_file = $this->root_path . $this->cache_data_dir . 'sqlcache_config_file_' . $this->dbhash . '.php'; @include($sqlcache_config_file); $this->starttime = time(); if ($this->max_cache_time && $this->starttime > $this->mysql_config_cache_file_time + $this->max_cache_time) { if  { $result = $this->link_id->query("SHOW VARIABLES LIKE 'basedir'"); $row = $result->fetch_array; $result->free(); if (!empty && $row['Value']{1} == ':' && !empty && $row['Value']{2} == "/") { $this->platform = 'WINDOWS'; } else { $this->platform = 'OTHER'; } } else { $this->platform = 'WINDOWS'; } if ($this->platform == 'OTHER' && ($dbhost != '.' && strtolower != 'localhost:3306' && $dbhost != '127.0.0.1:3306') || date_default_timezone_get { $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; $result->free(); if ($dbhost != '.' && strtolower != 'localhost:3306' && $dbhost != '127.0.0.1:3306') { $this->timeline = $this->starttime - $row['timeline']; } if (date_default_timezone_get { $this->timezone = $this->starttime - $row['timezone']; } } $content = 'mysql_config_cache_file_time = ' . $this->starttime . ";rn" . '$this->timeline = ' . $this->timeline . ";rn" . '$this->timezone = ' . $this->timezone . ";rn" . '$this->platform = ' . "'" . $this->platform . "';rn?" . '>'; @file_put_contents($sqlcache_config_file, $content); } /* 选择数据库 */ if  { if ($this->link_id->select_db { if  { $this->ErrorMsg("Can't select MySQL database; } return false; } else { return true; } } else { return true; } } function select_database { return $this->link_id->select_db; } function set_mysql_charset { if (in_array, array('gbk', 'big5', 'utf-8', 'utf8'))) { $charset = str_replace; } $this->link_id->set_charset; } function fetch_array($query, $result_type = MYSQLI_ASSOC) { $row = $query->fetch_array; $query->free(); return $row; } function query { 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[] = $sql; } if ($this->queryTime == '') { if (PHP_VERSION >= '5.0.0') { $this->queryTime = microtime; } else { $this->queryTime = microtime(); } } /* 当当前的时间大于类初始化时间的时候,自动执行 ping 这个自动重新连接操作 */ if  > $this->starttime + 1) { $this->link_id->ping(); } if (!($query = $this->link_id->query && $type != 'SILENT') { $this->error_message[]['message'] = 'MySQL Query Error'; $this->error_message[]['sql'] = $sql; $this->error_message[]['error'] = $this->link_id->error; $this->error_message[]['errno'] = $this->link_id->errno; $this->ErrorMsg(); return false; } if  &&  { $logfilename = $this->root_path . DATA_DIR . '/mysql_query_' . $this->dbhash . '_' . date . '.log'; $str = $sql . "nn"; if  { file_put_contents($logfilename, $str, FILE_APPEND); } else { $fp = @fopen; if  { fwrite; fclose; } } } 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->data_seek; $result = $query->fetch_row; return $result; } function num_rows { return $query->num_rows; } function num_fields { return $this->link_id->field_count; } function free_result { return $query->free(); } function insert_id() { return $this->link_id->insert_id; } function fetchRow { return $query->fetch_assoc(); } function fetch_fields { return $query->fetch_field(); } function version() { return $this->version; } function ping() { return $this->link_id->ping(); } function escape_string { return $this->link_id->real_escape_string; } function close() { return $this->link_id->close(); } function ErrorMsg($message = '', $sql = '') { if  { echo "DTXB info: $messagenn

"; //print('http://faq.comsenz.com/'); } else { echo "MySQL server error report:"; print_r; //echo "

error_message[2]['error']) . "' target='_blank'>http://faq.comsenz.com/"; } exit; }/* 仿真 Adodb 函数 */ function selectLimit($sql, $num, $start = 0) { if  { $sql .= ' LIMIT ' . $num; } else { $sql .= ' LIMIT ' . $start . ', ' . $num; } return $this->query; } function getOne($sql, $limited = false) { if  { $sql = trim; } $res = $this->query; if  { $row = $res->fetch_row; if  { return $row[0]; } else { return ''; } } else { return false; } } function getOneCached($sql, $cached = 'FILEFIRST') { $sql = trim; $cachefirst = ($cached == 'FILEFIRST' || ($cached == 'MYSQLFIRST' && $this->platform != 'WINDOWS')) && $this->max_cache_time; if  { return $this->getOne; } else { $result = $this->getSqlCacheData; if (empty($result['storecache']) == true) { return $result['data']; } } $arr = $this->getOne; if ($arr !== false && $cachefirst) { $this->setSqlCacheData; } return $arr; } function getAll { $res = $this->query; if  { $arr = $res->fetch_all; $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  { return $this->getAll; } else { $result = $this->getSqlCacheData

以上就是小编为大家带来的ecshop适应在PHP7的修改方法解决报错的实现全部内容了,希望大家多多支持脚本之家~

本文由手机购彩平台发布于手机购彩平台-编程,转载请注明出处:所以更改来继续使用吧

关键词: