版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、ecshop适应PHP7的修改说实话,ecshop这个系统,到目前也没见怎么推出新版本,如果是新项目,不太建议使用它。不过,因为我一直以来都在使用中,所以不得不更改让其适应PHP新版本。现在PHP 7已经出发行版了,所以更改来继续使用吧。具体的更改有以下方面:1、将mysql扩展的使用替换掉,改为使用mysqli或pdo:从php5.5 开始,mysql扩展将废弃了。这是个不小的工程,文件代码太长具体更改的文件在于 includes/cls_mysql.phpif (!defined('DITAN_ECS') die('Hacking attempt');cla
2、sscls_mysqlvar $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
3、=''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',
4、 $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 (defined ('EC_CHARSET')$charset = strtolower(str_replace('
5、-', '', EC_CHARSET);if (defined('ROOT_PATH') && ! $this->root_path)$this->root_path = ROOT_PATH;if ($quiet)$this->connect( $dbhost, $dbuser, $dbpw, $dbname, $charset, $pconnect, $quiet);else$this->settings = array('dbhost'=> $dbhost,'dbuser'
6、=> $dbuser,'dbpw'=> $dbpw,'dbname'=> $dbname'charset' => $charset,'pconnect' => $pconnect);function connect($dbhost, $dbuser, $dbpw, $dbname = '', $charset = 'utf8', $pconnect = 0, $quiet = 0)if ($pconnect)$this->link_id = new mysqli(
7、'p:'. $dbhost, $dbuser, $dbpw);if ($this->link_id->connect_error)if (!$quiet)$this->ErrorMsg("Can't pConnect MySQL Server( $dbhost)!");return false;else$this->link_id = new mysqli( $dbhost, $dbuser; $dbpw);if ($this->link_id->connect_error)if (! $quiet)$this-&
8、gt;ErrorMsg("Can't Connect MySQL 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( $charse1);$this->link_id->
9、query("SET sql_mode="");$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 >
10、; $this->mysql_config_cache_file_time +$this->max_cache_time)if ($dbhost !='.')$result = $this->link_id->query("SHOW VARIABLES LIKE 'basedir'");$row = $result->fetch_array(MYSQLI_ASSOC);$result->free();if (! empty($row'Value'1) && $row'
11、Value'1 = ':' && ! empty($row'Value'2) && $row'Value'2 = "/")$this->platform = 'WINDOWS'else$this->platform = 'OTHER'else$this->platform = 'WINDOWS'if ($this->platform = 'OTHER' &&date_default_t
12、imezone_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(MYSQLI_ASSOC);$result->free();$this->timeline = $this
13、->starttime - $row 'timeline'if (date_default_timezone_get() = 'UTC')$this->timezone = $this->starttime - $row'timezone'$content = '<' . "?phprn".'$this->mysql_config_cache_file_time = ' . $this->starttime . "rn".'$thi
14、s->timeline = ' . $this->timeline . "rn".'$this->timezone = ' . $this->timezone . "rn".'$this->platform = ' . $this->platform . "'rn?".'>'file_put_contents($sqlcache_config_file , $content);/*选择数据库*/if ($dbname)if ($t
15、his->link_id->select_db( $dbname) = false )if (!$quiet)$this->ErrorMsg("Can't select MySQL database( $dbname)!");return false;elsereturn true;elsereturn true;function select_database$dbname)return $this->link_id->select_db( $dbnam©function set_mysql_charset($charset
16、)if (in_array(strtolower($charse1), array('gbk', 'big5', 'utf-8', 'utf8')$charset = str_replace('-', '', $charset);$this->link_id->set_charset( $charse1);function fetch_array($query, $result_type = MYSQLI_ASSOC)$row = $query->fetch_array( $res
17、ult_type);$query->free();return $row;function query($sql, $type = ”)if ($this->link_id = NULL )$this->connect( $this->settings'dbhost', $this->settings'dbuse门,$this->settings'dbpw',$this->settings'dbname', $this->settings'charset', $this-&g
18、t;settings'pconnect');$this->settings = array();if ($this->queryCount+ <= 99)$this->queryLog = $sql;if ($this->queryTime ='')$this->queryTime = microtime (true);else$this->queryTime = microtime ();/*当当前的时间大于类初始化时间的时候,自动执行ping这个自动重新连接操作*/if (time() > $this->
19、starttime + 1)$this->link_id->p ing();if (!($query = $this->link_id->query( $sql) && $type != 'SILENT')$this->error_message'message' = 'MySQL Query Error'$this->error_message'sql' = $sql;$this->error_message'erro门=$this->link_id->
20、;error;$this->error_message'errno' = $this->link_id->errno;$this->ErrorMsg();if (defined('DEBUG_MODE') && (DEBUG_MODE & 8) = 8)$this->dbhash .$logfilename = $this->root_path . DATA_DIR . 7mysql_query_'.date('Y_m_d') . '.log'$str = $sq
21、l . "nn"if (PHP_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
22、->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
23、_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;funct
24、ion 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 ($messageecho "<b>DTXB info</b>: $messagdnn<br /><b
25、r />"print('<ahref=" z. com/?type=mysql&dberrno=2003&dberror=Can%27t%20connect%20to%20MyS QL%20server%20on" target="_blank"> z. com/</a>');elseecho "<b>MySQL server error report:"print_r ($this->error_message);/echo "<
26、;br /><br /><a href='". $this->error_message3'errno' . "&dberror=" . urlencode($this->error_message2'erro门)."' target='_blank'>>"exit;/*仿真 Adodb函数*/function selectLimit( $sql, $num, $start = 0)if ($start = 0)$sql .=
27、9; LIMIT ' . $num;else$sql .= ' LIMIT ' . $start . ', ' . $num;function getOne($sql, $limited = false)if ($limited = true)$sql = trim($sql . ' LIMIT 1');$res = $this->query($sql);if ($res != false)$row = $res->fetch_row();$res->free();if ($row != false)return $ro
28、w0;elsereturn ''elsereturn false;function getOneCached$sql, $cached = 'FILEFIRST')$sql = trim ($sql . ' LIMIT 1');$cachefirst = ($cached = 'FILEFIRST' | ( $cached = 'MYSQLFIRST' &&$this->platform !='WINDOWS') && $this->max_cache_t
29、ime;if (!$cachefirst)return $this->getOne($sql, true);else$result = $this->getSqlCacheData($sql, $cached);if (empty($result'storecache') = true)return $result'data'$arr = $this->getOne($sql, true);if ($arr != false && $cachefirst)$this->setSqlCacheData($result, $a
30、rr);return $arr;function getAll( $sql)$res = $this->query($sql);if ($res != false)$arr = $res->fetch_all(MYSQ LI_ASSOC);$res->free();return $arr;elsereturn false;function getAllCached( $sql, $cached = 'FILEFIRST')$cachefirst = ($cached = 'FILEFIRST' | ( $cached = 'MYSQLF
31、IRST' &&$this->platform !='WINDOWS') && $this->max_cache_time;if (!$cachefirst)return $this->getAll( $sql);else$result = $this->getSqlCacheData($sql, $cached);if (empty($result'storecache') = true)$arr = $this->getAII( $sql);if ($arr != false &&
32、amp; $cachefirst)$this->setSqlCacheData($result, $arr);return $arr;function getRow($sql, $limited = false)if ($limited = true)$sql = trim($sql . ' LIMIT 1');$res = $this->query($sql);if ($res != false)$result = $res->fetch_assoc();$res->free();return $result;elsereturn false;func
33、tion getRowCached($sql, $cached = 'FILEFIRST')$cachefirst = ($cached = 'FILEFIRST' | ( $cached = 'MYSQLFIRST' &&$this->platform !='WINDOWS') && $this->max_cache_time;if (!$cachefirst)return $this->getRow($sql, true);else$result = $this->get
34、SqlCacheData($sql, $cached);if (empty($result'storecache') = true)return $result'data'$arr = $this->getRow( $sql, true);if ($arr != false && $cachefirst)$this->setSqlCacheData($result, $arr);return $arr;function getCol($sql)$res = $this->query($sql);if ($res != false
35、)$arr = array();while ($row = $res->fetch_row()$arr = $row0;$res->free();return $arr;elsereturn false;function getColCached($sql, $cached = 'FILEFIRST')$cachefirst = ($cached = 'FILEFIRST' | ( $cached = 'MYSQLFIRST' &&$this->platform !='WINDOWS') &
36、;& $this->max_cache_time;if (!$cachefirst)return $this->getCol( $sql);else='')implode(',',$result = $this->getSqlCacheData($sql, $cached); if (empty($result'storecache') = true)return $result'data'$arr = $this->getCol( $sql);if ($arr != false &&
37、; $cachefirst)$this->setSqlCacheData($result, $arr);return $arr;function autoExecute($table, $field_values, $mode = 'INSERT', $where = '', $querymode$field_names = $this->getCol('DESC ' . $table);$sql =''if ($mode = 'INSERT')$fields = $values = array();f
38、oreach ($field_names AS $value)if (array_key_exists( $value, $field_values) = true)$fields = $value;$values = ""' . $field_values $value.""'if (!empty($fields)$sql = 'INSERT INTO ' . $table . ' (' . implode(', ', $fields) . ') VALUES ('.$va
39、lues).')'else$sets = array();foreach ($field_names AS $value)if (array_key_exists($value, $field_values) = true)$sets = $value . " = '" . $field_values $value.""'if (!empty($sets)$sql = 'UPDATE ' . $table . ' SET ' . implode (', ', $sets) .
40、 ' WHERE ' . $where;if ($sql)return $this->query($sql, $querymode);elsereturn false;function autoReplace($table, $field_values, $update_values, $where = '', $querymode ='')$field_descs = $this->getAII('DESC ' . $table);$primary_keys = array();foreach ($field_des
41、cs AS $value)$field_names = $value'Field'if ($value'Key' = 'P RI')$primary_keys = $value'Field'$fields = $values = array();foreach ($field_names AS $value)if (array_key_exists($value, $field_values) = true)$fields = $value;$values = ""' . $field_values $
42、value.""'$sets = array();foreach ($update_valuesAS $key => $value)if (array_key_exists($key, $field_values) = true)if (is_int($value) | is_float ($value)$sets = $key . ' = ' . $key . ' + ' . $value;else$sets = $key . " = '" . $value .;$sql = ”;if (empty
43、($primary_keys)if (!empty($fields)$sql = 'INSERT INTO ' . $table . ' (' . implode(', ', $fields) . ') VALUES (' . implode(',', $values).')'elseif ($this->version() >= 41')if (! empty( $fields)$sql = 'INSERT INTO ' . $table . ' (
44、39; . implode(', ', $fields) . ') VALUES ('. implode(', ', $values).')'if (! empty($sets)$sql .= 'ON DUPLICATE KEY UPDATE ' . implode (', ', $sets);if (empty($where)$where = array();foreach ($primary_keys AS $value)if (is_numeric ($value)$where = $valu
45、e . ' = ' . $field_values$value;else$where = $value . " = '" . $field_values $value.""'$where = implode(' AND ', $where);if ($where && (! empty($sets) | !empty($fields)if (intval ($this->getOne("SELECT COUNT(*) FROM $table WHERE $where"
46、;) >0)if (! empty($sets)$sql = 'UPDATE ' . $table . ' SET ' . implode (', ', $sets) . ' WHERE '. $where;elseif (! empty( $fields)$sql = 'REPLACE INTO ' . $table . ' (' . implode(', ', $fields) . ') VALUES ('.implode(', ', $va
47、lues).')'if ($sql)return $this->query($sql, $querymode);else return false;function setMaxCacheTime($seconc) $this->max_cache_time = $second;function getMaxCacheTime()return $this->max_cache_time;function getSqlCacheData($sql, $cached ='')$sql = trim ($sql);$result = array();
48、$result'filename' = $this->root_path . $this->cache_data_dir . 'sqlcache_'.abs(crc32($this->dbhash . $sql) . '_' . md5($this->dbhash . $sql) . '.php'$data = file_get_contents($result'filename');if (isset($data23)$filetime = substr($data, 13, 10);$d
49、ata = substr($data, 23);if ($cached = 'FILEFIRST' && time() > $filetime + $this->max_cache_time) | ($cached = 'MYSQLFIRST' && $this->table_lastupdate($this->get_table_name($sql) > $filetime )$result 'storecache' = true;else$result'data'
50、= unserialize($data);if ($result'data' = false)$result'storecache' = true;$result'storecache' = false;else$result 'storecache' = true;return $result;function setSqlCacheData($result, $data)if ($result'storecache' = true && $result'filename')fil
51、e_put_contents($result'filename', '<?php exit;?' . time() . serialize($data); clearstatcache();/*获取SQL语句中最后更新的表的时间,有多个表的情况下,返回最新的表的时间*/function table_lastupdate($tables)if ($this->link_id = NULL )$this->connect( $this->settings'dbhost', $this->settings'dbus
52、e门,$this->settings'dbpw',$this->settings'dbname', $this->settings'charset', $this->settings'pconnect');$this->settings = array();$lastupdatetime = '0000-00-00 00:00:00'$tables = str_replace('、',",$tables);$this->mysql_disable_cac
53、he_tables = str_replace('、',",$this->mysql_disable_cache_tables);foreach ($tables AS $table)if (in_array($table, $this->mysql_disable_cache_tables) = true)$lastupdatetime = '2037-12-31 23:59:59: break;if (strstr($table, != NULL )$tmp = explode('.', $table);$sql = '
54、SHOW TABLE STATUS FROM、' . trim ($tmp0) . "' LIKE '" . trim ($tmp1).else$sql = "SHOW TABLE STATUS LIKE '" . trim($table).;$result = $this->link_id->query( $sql);$row = $result->fetch_assoc();if ($row'Update_time' > $lastupdatetime)$lastupdateti
55、me = $row'Update_time'$lastupdatetime = strtotime($lastupdatetime) - $this->timezone + $this->timeline;return $lastupdatetime;function get_table_name($query_item)$query_item = trim ($query_item);$table_names = array();/*判断语句中是不是含有JOIN */if (stristr($query_item, ' JOIN ')='&
56、#39;)/*解析一般的 SELECT FROM语句*/if(preg_match(7ASELECT.*?FROMs*(?:'?w+'?s*.s*)?'?w+'?(?:(?:s*AS)?s*'?w+'?)?(?:s*,s*(?:'?w+'?s*.s*)?'?w+'?(?:(?:s*AS)?s*'?w+'?)?)*)/is', $query_item, $table_names)$table_names = preg_replace('/(?:'?w+'?s*.s*)?
57、'?w+'?)A,*/', '1', $table_names1);return preg_split('/s*,s*/', $table_names);if(preg_match(7ASELECT.*?FR0Ms*(?:'?w+'?s*.s*)?'?w+'?)(?:(?:s*AS)?s*'?w+'?)?.*?J0IN.*$/is',$query_item, $table_names)$other_table_names = array();preg_match_all(7J0INs
58、*(?:'?w+'?s*.s*)?'?w+'?)s*/i',$query_item,$other_table_name$;return array_merge(array($table_names1), $other_table_name$1);return $table_names/*设置不允许进行缓存的表*/function set_disable_cache_tables$tables)if (!is_array($tables)$tables = explode(',', $tables);foreach ($tables AS
59、$table)$this->mysql_disable_cache_tables = $table;array_unique($this->mysql_disable_cache_tables);+*启动事务+* access public+* return void+*/public function startTrans() $this->initConnect(true);if ( !$this->link_id ) return false;/数据rollback支持if ($this->transTimes = 0) $this->link_id-
60、>autocommit( FALSE);$this->transTimes+;return ;/*+*用于非自动提交状态下面的查询提交+* access public+* return boolen+*/public function commit()if ($this->transTimes > 0) $result = $this->link_id->commit();$this->transTimes = 0;if(!$result)$this->error_message'message' = 'MySQL Que
61、ry Error'$this->error_message'sql' = $sql;$this->error_message'erro门=$this->link_id->error; $this->error_message'errno' = $this->link_id->errno; $this->ErrorMsg();return false;return true;/*+*事务回滚+* access public+ * return boolen+*/public function rollback()if ($this->transTimes > 0) $result = $this->link_id->rollback();$this->transTimes = 0;if(!$result)$this->error_message'message' = 'MySQL Query Error'$this->error_message'sql' =
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2024水钻安装工程中的设备租赁与维护合同
- 2025年佛山年货运资格证考试题
- 2025年度精制粉生产线能源管理系统采购合同2篇
- 2024版试用销售合同范本
- 二零二五年度古玩字画鉴定修复与交易合同3篇
- 二零二五年工业废钢资源化利用合作协议3篇
- 2024股权代持违约责任协议
- 2025版借款合同书类图片素材60张在线编辑授权3篇
- 浙教版2023小学信息技术五年级上册 第14课《算法的验证》说课稿及反思
- 小学信息技术四年级上册第1课《制作月历》说课稿
- 电动汽车胶粘剂市场洞察报告
- 不锈钢楼梯扶手安装合同
- 开荒保洁物业管理开荒保洁服务实施方案
- GA/T 2015-2023芬太尼类药物专用智能柜通用技术规范
- 新华DCS软件2.0版使用教程-文档资料
- 住所的承诺书范文
- 售前解决方案部门管理规章制度
- 幼儿园游戏活动材料投放与指导课件
- 《城市道路工程设计规范》宣贯
- 电力工程管理培训课件
- 志愿服务证明(多模板)
评论
0/150
提交评论