登錄 注冊 發(fā)新帖 |
耶耶耶
|
||
發(fā)帖時間:2021-4-8 |
查看數:0 |
回復數:25
|
baidu2018
|
服務器版本php過高,可以試試升級mysql連接。去百度搜索:TWCMS支持PHP7.1.9替換文件。應該可以解決
2021-4-9
#2樓
|
耶耶耶
|
感謝感謝,我去試試
2021-4-9
#3樓
|
ikezhuo
|
引用 耶耶耶: 必須開啟關閉[×] (關閉將無法使用本系統(tǒng)) 這個怎么辦啊,godaddy的虛擬空間,cpanel 兄弟,我也遇到和你一樣的問題,花了一星期時間幫朋友換了CMS系統(tǒng)勉強能用,要是你找到解決方法說一聲。 ![]()
2021-4-10
#4樓
|
耶耶耶
|
引用 ikezhuo: 兄弟,我也遇到和你一樣的問題,花了一星期時間幫朋友換了CMS系統(tǒng)勉強能用,要是你找到解決方法說一聲。 補個鏈接:http://www.gzaune.com/ 兄弟,樓上說了,降低版本
2021-4-19
#5樓
|
耶耶耶
|
引用 ikezhuo: 兄弟,我也遇到和你一樣的問題,花了一星期時間幫朋友換了CMS系統(tǒng)勉強能用,要是你找到解決方法說一聲。 補個鏈接:http://www.gzaune.com/
2021-4-19
#6樓
|
耶耶耶
|
2021-4-19
#7樓
|
ikezhuo
|
引用 耶耶耶: 兄弟,樓上說了,降低版本 但主機后臺面板不能更換PHP版本。
2021-4-22
#8樓
|
sbqwg
|
先找個php5.6的空間安裝上,再修改一下數據庫連接方式。 直接上php8.0。 第二步:db_mysqli.class.php ,路徑:網站根目錄/twcms/kongphp/db/。 <?php defined('KONG_PATH') || exit; class db_mysqli implements db_interface { private $conf; public $tablepre; // 數據表前綴 //private $wlink; // 寫(主)數據庫 //private $rlink; // 讀(從)數據庫 //private $xlink; // 分發(fā)數據庫 public function __construct(&$conf) { $this->conf = &$conf; $this->tablepre = $conf['master']['tablepre']; } /** * 創(chuàng)建 MySQL 連接 * @param string $var 數據庫鏈接名 只能是 wlink rlink xlink * @return resource */ public function __get($var) { // 主數據庫 (寫) if($var == 'wlink') { $cfg = $this->conf['master']; empty($cfg['engine']) && $cfg['engine'] = ''; $this->wlink = $this->connect($cfg['host'], $cfg['user'], $cfg['password'], $cfg['name'], $cfg['charset'], $cfg['engine']); return $this->wlink; // 從數據庫群 (讀) }elseif($var == 'rlink') { if(empty($this->conf['slaves'])) { $this->rlink = $this->wlink; return $this->rlink; } $n = rand(0, count($this->conf['slaves']) - 1); $cfg = $this->conf['slaves'][$n]; empty($cfg['engine']) && $cfg['engine'] = ''; $this->rlink = $this->connect($cfg['host'], $cfg['user'], $cfg['password'], $cfg['name'], $cfg['charset'], $cfg['engine']); return $this->rlink; // 單點分發(fā)數據庫 (負責所有表的 maxid count 讀寫) }elseif($var == 'xlink') { if(empty($this->conf['arbiter'])) { $this->xlink = $this->wlink; return $this->xlink; } $cfg = $this->conf['arbiter']; empty($cfg['engine']) && $cfg['engine'] = ''; $this->xlink = $this->connect($cfg['host'], $cfg['user'], $cfg['password'], $cfg['name'], $cfg['charset'], $cfg['engine']); return $this->xlink; } } /** * 讀取一條數據 * @param string $key 鍵名 (高性能需求,鍵名必須使用索引字段) * @return array */ // string // in: 'user-uid-2' // out: array('uid'=>2, 'username'=>'two') public function get($key) { list($table, $keyarr, $keystr) = $this->key2arr($key); $query = $this->query("SELECT * FROM {$this->tablepre}$table WHERE $keystr LIMIT 1", $this->rlink); return mysqli_fetch_assoc($query); } /** * 讀取多條數據 * @param array $keys 鍵名數組 (高性能需求,鍵名必須使用索引字段) * @return array */ // array // in: array( // 'article-cid-1-aid-1', // 'article-cid-1-aid-2', // ) // out: array( // 'article-cid-1-aid-1'=>array('cid'=>1,'cid'=>1, 'title'=>'abc') // 'article-cid-1-aid-2'=>array('cid'=>1,'cid'=>2, 'title'=>'bcd') // ) public function multi_get($keys) { // 下面這種方式讀取比遍歷讀取效率高 $sql = ''; $ret = array(); foreach($keys as $k) { $ret[$k] = array(); // 按原來的順序賦值,避免后面的 OR 條件取出時順序混亂 list($table, $keyarr, $keystr) = $this->key2arr($k); $sql .= "$keystr OR "; } $sql = substr($sql, 0, -4); if($sql) { $query = $this->query("SELECT * FROM {$this->tablepre}$table WHERE $sql", $this->rlink); while($row = mysqli_fetch_assoc($query)) { $keyname = $table; foreach($keyarr as $k=>$v) { $keyname .= "-$k-".$row[$k]; } $ret[$keyname] = $row; } } return $ret; } /** * 寫入一條數據 (包含了 insert 和 update) * @param string $key 鍵名 * @param array $data 數據 * @return bool */ public function set($key, $data) { if(!is_array($data)) return FALSE; list($table, $keyarr) = $this->key2arr($key); $data += $keyarr; $s = $this->arr2sql($data); $exists = $this->get($key); if(empty($exists)) { return $this->query("INSERT INTO {$this->tablepre}$table SET $s", $this->wlink); } else { return $this->update($key, $data); } } /** * 更新一條數據 (相比 $this->set() 可以修改主鍵) * @param string $key 鍵名 * @param array $data 數據 * @return bool */ public function update($key, $data) { list($table, $keyarr, $keystr) = $this->key2arr($key); $s = $this->arr2sql($data); return $this->query("UPDATE {$this->tablepre}$table SET $s WHERE $keystr LIMIT 1", $this->wlink); } /** * 刪除一條數據 * @param string $key 鍵名 * @return bool */ public function delete($key) { list($table, $keyarr, $keystr) = $this->key2arr($key); return $this->query("DELETE FROM {$this->tablepre}$table WHERE $keystr LIMIT 1", $this->wlink); } /** * 讀取/設置 表最大ID * @param string $key 鍵名 只能是表名+一個字段 如:'user-uid'(uid為自增字段) * @param boot/int $val 設置值 有三種情況 1.不填為讀取(默認) 2.基礎上增加 如:'+1' 3.設置指定值 * @return int */ // maxid('user-uid') 讀取 user 表最大 uid // maxid('user-uid', '+1') 設置 maxid + 1, 用于占位,保證 key 不會重復 // maxid('user-uid', 10000) 設置 maxid 為 10000 public function maxid($key, $val = FALSE) { list($table, $col) = explode('-', $key); $maxid = $this->table_maxid($key); if($val === FALSE) { return $maxid; }elseif(is_string($val)) { $val = max(0, $maxid + intval($val)); } $this->query("UPDATE {$this->tablepre}framework_maxid SET maxid='$val' WHERE name='$table' LIMIT 1", $this->xlink); return $val; } /** * 讀取表最大ID (如果不存在自動創(chuàng)建表和設置最大ID) * @param string $key 鍵名 只能是表名+一個字段 如:'user-uid'(uid一般為主鍵) * @return int */ public function table_maxid($key) { list($table, $col) = explode('-', $key); $maxid = FALSE; $query = $this->query("SELECT maxid FROM {$this->tablepre}framework_maxid WHERE name='$table' LIMIT 1", $this->xlink, FALSE); if($query) { $maxid = $this->result($query, 0); }elseif(mysqli_errno($this->xlink) == 1146) { $sql = "CREATE TABLE `{$this->tablepre}framework_maxid` ("; $sql .= "`name` char(32) NOT NULL default '',"; $sql .= "`maxid` int(10) unsigned NOT NULL default '0',"; $sql .= "PRIMARY KEY (`name`)"; $sql .= ") ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci"; $this->query($sql, $this->xlink); }else{ throw new Exception('framework_maxid error, mysql_error:'.mysqli_error($this->xlink)); } if($maxid === FALSE) { $query = $this->query("SELECT MAX($col) FROM {$this->tablepre}$table", $this->wlink); $maxid = $this->result($query, 0); $this->query("INSERT INTO {$this->tablepre}framework_maxid SET name='$table', maxid='$maxid'", $this->xlink); } return $maxid; } /** * 讀取/設置 表的總行數 * @param string $table 表名 * @param boot/int $val 設置值 有四種情況 1.不填為讀取(默認) 2.基礎上增加 如:'+1' 3.基礎上減少 如:'-1' 4.設置指定值 * @return int */ public function count($table, $val = FALSE) { $count = $this->table_count($table); if($val === FALSE) { return $count; }elseif(is_string($val)) { if($val[0] == '+') { $val = $count + intval($val); }elseif($val[0] == '-') { $val = max(0, $count + intval($val)); } } $this->query("UPDATE {$this->tablepre}framework_count SET count='$val' WHERE name='$table' LIMIT 1", $this->xlink); return $val; } /** * 讀取表的總行數 (如果不存在自動創(chuàng)建表和設置總行數) * @param string $table 表名 * @return int */ public function table_count($table) { $count = FALSE; $query = $this->query("SELECT count FROM {$this->tablepre}framework_count WHERE name='$table' LIMIT 1", $this->xlink, FALSE); if($query) { $count = $this->result($query, 0); }elseif(mysqli_errno($this->xlink) == 1146) { $sql = "CREATE TABLE {$this->tablepre}framework_count ("; $sql .= "`name` char(32) NOT NULL default '',"; $sql .= "`count` int(10) unsigned NOT NULL default '0',"; $sql .= "PRIMARY KEY (`name`)"; $sql .= ") ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci"; $this->query($sql, $this->xlink); }else{ throw new Exception('framework_cout error, mysql_error:'.mysqli_error($this->xlink)); } if($count === FALSE) { $query = $this->query("SELECT COUNT(*) FROM {$this->tablepre}$table", $this->wlink); $count = $this->result($query, 0); $this->query("INSERT INTO {$this->tablepre}framework_count SET name='$table', count='$count'", $this->xlink); } return $count; } /** * 清空表 * @param string $table 表名 (表不存在會報錯,但無關緊要) * @return int */ public function truncate($table) { try { $this->query("TRUNCATE {$this->tablepre}$table"); return TRUE; } catch(Exception $e) { return FALSE; } } /** * 根據條件讀取數據 (返回數組) * @param string $table 表名 * @param array $pri 主鍵 * @param array $where 條件 * @param array $order 排序 * @param int $start 開始位置 * @param int $limit 讀取幾條 * @return array */ // in: // find_fetch('user', 'uid', array('uid'=> 100), array('uid'=>1), 0, 10); // find_fetch('user', 'uid', array('uid'=> array('>'=>'100', '<'=>'200')), array('uid'=>1), 0, 10); // find_fetch('user', 'uid', array('username'=> array('LIKE'=>'abc'), array('uid'=>1), 0, 10); // out: // array( // 'user-uid-1'=>array('uid'=>1, 'username'=>'zhangsan'), // 'user-uid-2'=>array('uid'=>2, 'username'=>'lisi'), // 'user-uid-3'=>array('uid'=>3, 'username'=>'wangwu'), // ) public function find_fetch($table, $pri, $where = array(), $order = array(), $start = 0, $limit = 0) { $key_arr = $this->find_fetch_key($table, $pri, $where, $order, $start, $limit); if(empty($key_arr)) return array(); return $this->multi_get($key_arr); } /** * 根據條件返回 key 數組 * @param string $table 表名 * @param array $pri 主鍵 * @param array $where 條件 * @param array $order 排序 * @param int $start 開始位置 * @param int $limit 讀取幾條 * @return array */ // out: // array ( // 'user-uid-1', // 'user-uid-2', // 'user-uid-3', // ) public function find_fetch_key($table, $pri, $where = array(), $order = array(), $start = 0, $limit = 0) { $pris = implode(',', $pri); $s = "SELECT $pris FROM {$this->tablepre}$table"; $s .= $this->arr2where($where); if(!empty($order)) { $s .= ' ORDER BY '; $comma = ''; foreach($order as $k=>$v) { $s .= $comma."$k ".($v == 1 ? ' ASC ' : ' DESC '); $comma = ','; } } $s .= ($limit ? " LIMIT $start,$limit" : ''); $ret = array(); $query = $this->query($s, $this->rlink); while($row = mysqli_fetch_assoc($query)) { $keystr = ''; foreach($pri as $k) { $keystr .= "-$k-".$row[$k]; } $ret[] = $table.$keystr; } return $ret; } /** * 根據條件批量更新數據 * @param string $table 表名 * @param array $where 條件 * @param array $lowprority 是否開啟不鎖定表 * @return int 返回影響的記錄行數 */ public function find_update($table, $where, $data, $lowprority = FALSE) { $where = $this->arr2where($where); $data = $this->arr2sql($data); $lpy = $lowprority ? 'LOW_PRIORITY' : ''; $this->query("UPDATE $lpy {$this->tablepre}$table SET $data $where", $this->wlink); return mysqli_affected_rows($this->wlink); } /** * 根據條件批量刪除數據 * @param string $table 表名 * @param array $where 條件 * @param array $lowprority 是否開啟不鎖定表 * @return int 返回影響的記錄行數 */ public function find_delete($table, $where, $lowprority = FALSE) { $where = $this->arr2where($where); $lpy = $lowprority ? 'LOW_PRIORITY' : ''; $this->query("DELETE $lpy FROM {$this->tablepre}$table $where", $this->wlink); return mysqli_affected_rows($this->wlink); } /** * 準確獲取最大ID * @param string $key 鍵名 * @return int */ public function find_maxid($key) { list($table, $maxid) = explode('-', $key); $arr = $this->fetch_first("SELECT MAX($maxid) AS num FROM {$this->tablepre}$table"); return isset($arr['num']) ? intval($arr['num']) : 0; } /** * 準確獲取總條數 * @param string $table 表名 * @param array $where 條件 * @return int */ public function find_count($table, $where = array()) { $where = $this->arr2where($where); $arr = $this->fetch_first("SELECT COUNT(*) AS num FROM {$this->tablepre}$table $where"); return isset($arr['num']) ? intval($arr['num']) : 0; } /** * 創(chuàng)建索引 * @param string $table 表名 * @param array $index 鍵名數組 // array('uid'=>1, 'dateline'=>-1, 'unique'=>TRUE, 'dropDups'=>TRUE) 為了配合 mongodb 的索引才這樣設計的 * @return boot */ public function index_create($table, $index) { $keys = implode(',', array_keys($index)); $keyname = implode('_', array_keys($index)); return $this->query("ALTER TABLE {$this->tablepre}$table ADD INDEX $keyname($keys)", $this->wlink); } /** * 刪除索引 * @param string $table 表名 * @param array $index 鍵名數組 * @return boot */ public function index_drop($table, $index) { $keys = implode(',', array_keys($index)); $keyname = implode('_', array_keys($index)); return $this->query("ALTER TABLE {$this->tablepre}$table DROP INDEX $keyname", $this->wlink); } // +------------------------------------------------------------------------------ // | 以下是公共方法,但不推薦外部使用 // +------------------------------------------------------------------------------ /** * 連接 MySQL 服務器 * @param string $host 主機 * @param string $user 用戶名 * @param string $pass 密碼 * @param string $name 數據庫名稱 * @param string $charset 字符集 * @param string $engine 數據庫引擎 * @return resource */ public function connect($host, $user, $pass, $name, $charset = 'utf8', $engine = '') { $link = mysqli_connect($host, $user, $pass,$name); if(!$link) { throw new Exception(mysqli_error($link)); } $result = mysqli_select_db($link,$name); if(!$result) { throw new Exception(mysqli_error($link)); } if(!empty($engine) && $engine == 'InnoDB') { $this->query("SET innodb_flush_log_at_trx_commit=no", $link); } // 不考慮 mysql 5.0.1 下以版本 $this->query("SET character_set_connection=$charset, character_set_results=$charset, character_set_client=binary, sql_mode=''", $link); //$this->query("SET names utf8, sql_mode=''", $link); return $link; } /** * 發(fā)送一條 MySQL 查詢 * @param string $sql SQL 語句 * @param string $link 打開的連接 * @param boot $isthrow 錯誤時是否拋 * @return resource */ public function query($sql, $link = NULL, $isthrow = TRUE) { empty($link) && $link = $this->wlink; if(defined('DEBUG') && DEBUG && isset($_ENV['_sqls']) && count($_ENV['_sqls']) < 1000) { $start = microtime(1); $result = mysqli_query( $link,$sql); $runtime = number_format(microtime(1) - $start, 4); // explain 分析 select 語句 $explain_str = ''; if(substr($sql, 0, 6) == 'SELECT') { $query = mysqli_query($link,"explain $sql"); if($query !== FALSE) { $explain_arr = mysqli_fetch_assoc($query); //print_r($explain_arr); $explain_str = ' <font color="blue">[explain type: '.$explain_arr['type'].' | rows: '.$explain_arr['rows'].']</font>'; } } $_ENV['_sqls'][] = ' <font color="red">[time:'.$runtime.'s]</font> '.htmlspecialchars(stripslashes($sql)).$explain_str; }else{ $result = mysqli_query($link,$sql); } if(!$result && $isthrow) { $s = 'MySQL Query Error: <b>'.$sql.'</b>. '.mysqli_error($link); if(defined('DEBUG') && !DEBUG) $s = str_replace($this->tablepre, '***', $s); // 防止泄露敏感信息 throw new Exception($s); } $_ENV['_sqlnum']++; return $result; } /** * 獲取第一條數據 * @param string $sql SQL 語句 * @param string $link 打開的連接 * @return array */ public function fetch_first($sql, $link = NULL) { empty($link) && $link = $this->rlink; $query = $this->query($sql, $link); return mysqli_fetch_assoc($query); } /** * 獲取多條數據 (特殊情況會用到) * @param string $sql SQL 語句 * @param string $link 打開的連接 * @return array */ public function fetch_all($sql, $link = NULL) { empty($link) && $link = $this->rlink; $query = $this->query($sql, $link); $ret = array(); while($row = mysqli_fetch_assoc($query)) { $ret[] = $row; } return $ret; } /** * 獲取結果數據 * @param resource $query 查詢結果集 * @param int $row 第幾列 * @return int */ public function result($query, $row) { //~ return mysqli_num_rows($query) ? intval(mysqli_data_seek($query, $row)) : FALSE; if (!mysqli_num_rows($query)) return FALSE; mysqli_data_seek($query, $row); $rowdata = mysqli_fetch_row($query); return $rowdata[$row]; } /** * 獲取 mysql 版本 * @return string */ public function version() { return mysqli_get_server_info($this->rlink); } /** * 關閉讀寫數據庫連接 */ public function __destruct() { if(!empty($this->wlink)) { mysqli_close($this->wlink); } if(!empty($this->rlink) && !empty($this->wlink) && $this->rlink != $this->wlink) { mysqli_close($this->rlink); } } /** * 將數組轉換為 where 語句 * @param array $arr 數組 * @return string * in: array('id'=> array('>'=>'10', '<'=>'200')) * out: WHERE id>'10' AND id<'200' * 支持: '>=', '<=', '>', '<', 'LIKE', 'IN' (盡量少用,能不用則不用。'LIKE' 會導致全表掃描,大數據時不要使用) * 注意1: 為考慮多種數據庫兼容和性能問題,其他表達式不要使用,如:!= 會導致全表掃描 * 注意2: 高性能準則要讓SQL走索引,保證查詢至少達到range級別 */ private function arr2where($arr) { $s = ''; if(!empty($arr)) { foreach($arr as $key=>$val) { if(is_array($val)) { foreach($val as $k=>$v) { if(is_array($v)) { if($k === 'IN' && $v) { foreach($v as $i) { $i = addslashes($i); $s .= "$key='$i' OR "; // 走索引時,OR 比 IN 快 } $s = substr($s, 0, -4).' AND '; } }else{ $v = addslashes($v); if($k === 'LIKE') { $s .= "$key LIKE '%$v%' AND "; }else{ $s .= "$key$k'$v' AND "; } } } }else{ $val = addslashes($val); $s .= "$key='$val' AND "; } } $s && $s = ' WHERE '.substr($s, 0, -5); } return $s; } /** * 將數組轉換為SQL語句 * @param array $arr 數組 * @return string * in: array('cid'=>1, 'aid'=>2) * out: cid='1',aid='2' */ private function arr2sql($arr) { $s = ''; foreach($arr as $k=>$v) { $v = addslashes($v); $s .= "$k='$v',"; } return rtrim($s, ','); } /** * 將鍵名轉換為數組 * @param string $key 鍵名 * @return array * in: article-cid-1-aid-2 * out: array('article', array('cid'=>1, 'aid'=>2), 'cid=1 AND aid=2') */ private function key2arr($key) { $arr = explode('-', $key); if(empty($arr[0])) { throw new Exception('table name is empty.'); } $table = $arr[0]; $keyarr = array(); $keystr = ''; $len = count($arr); for($i = 1; $i < $len; $i = $i + 2) { if(isset($arr[$i + 1])) { $v = $arr[$i + 1]; $keyarr[$arr[$i]] = is_numeric($v) ? intval($v) : $v; // 因為 mongodb 區(qū)分數字和字符串 $keystr .= ($keystr ? ' AND ' : '').$arr[$i]."='".addslashes($v)."'"; } else { $keyarr[$arr[$i]] = NULL; } } if(empty($keystr)) { throw new Exception('keystr name is empty.'); } return array($table, $keyarr, $keystr); } } ?> 第三步:修改網站的配置文件就,/網站根目錄/twcms/config/config.inc.php // 數據庫配置,type 為默認的數據庫類型,可以支持多種數據庫: mysql|pdo_mysql|pdo_sqlite|postgresql|mongodb 'db' => array( 'type' => 'mysqli', // 主數據庫 'master' => array( 'host' => 'localhost',
2021-11-14
#9樓
|
baidu2018
|
你這方法不行的。
2021-11-16
#10樓
|
qq89408497
|
發(fā)帖啊
2022-3-29
#11樓
|
lxz168
|
而擼金幣回復
2023-1-1
#12樓
|
lxz168
|
而擼金幣回復
2023-1-1
#13樓
|
lxz168
|
而擼金幣回復
2023-1-1
#14樓
|
lxz168
|
而擼金幣回復
2023-1-1
#15樓
|
lxz168
|
而擼金幣回復
2023-1-1
#16樓
|
lxz168
|
而擼金幣回復
2023-1-1
#17樓
|
lxz168
|
而擼金幣回復
2023-1-1
#18樓
|
lxz168
|
而擼金幣回復
2023-1-1
#19樓
|
lxz168
|
而擼金幣回復
2023-1-1
#20樓
|
游客組
|
|