mysql 改成 mysqli 问题

b15365637 2019-12-20 06:58:16
mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead | olcms/libs/classes/mysql.class.php | 57
程序有这个报错

网上方法
将mysql改为mysqli,你可能会觉得要改的很多,其实并不多,一般的只需改mysql.class.php文件就可以了。
比如说将
mysql_connect($server, $username, $password)

改为
mysqli_connect($server, $username, $password,$database)



我的程序
	public function connect() {
$func = $this->config['pconnect'] == 1 ? 'mysql_pconnect' : 'mysql_connect';
if(!$this->link = @$func($this->config['hostname'], $this->config['username'], $this->config['password'], 1)) {
$this->halt('Can not connect to MySQL server');
return false;
}

if($this->version() > '4.1') {
$charset = isset($this->config['charset']) ? $this->config['charset'] : '';
$serverset = $charset ? "character_set_connection='$charset',character_set_results='$charset',character_set_client=binary" : '';
$serverset .= $this->version() > '5.0.1' ? ((empty($serverset) ? '' : ',')." sql_mode='' ") : '';
$serverset && mysql_query("SET $serverset", $this->link);
}

if($this->config['database'] && !@mysql_select_db($this->config['database'], $this->link)) {
$this->halt('Cannot use database '.$this->config['database']);
return false;
}
$this->database = $this->config['database'];
return $this->link;
}

我改后

public function connect() {
$func = $this->config['pconnect'] == 1 ? 'mysql_pconnect' : 'mysqli_connect';
if(!$this->link = @$func($this->config['hostname'], $this->config['username'], $this->config['password'], $this->config['database'])) {
$this->halt('Can not connect to MySQL server');
return false;
}

if($this->version() > '4.1') {
$charset = isset($this->config['charset']) ? $this->config['charset'] : '';
$serverset = $charset ? "character_set_connection='$charset',character_set_results='$charset',character_set_client=binary" : '';
$serverset .= $this->version() > '5.0.1' ? ((empty($serverset) ? '' : ',')." sql_mode='' ") : '';
$serverset && mysql_query("SET $serverset", $this->link);
}

if($this->config['database'] && !@mysql_select_db($this->config['database'], $this->link)) {
$this->halt('Cannot use database '.$this->config['database']);
return false;
}
$this->database = $this->config['database'];
return $this->link;
}


这样改后 网站打不开了超时 显示不出来
这个到底怎么改呢?
完整的mysql.class.php代码 http://www.126z.net/mysql.class.zip
...全文
441 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
廖展程 2020-01-14
  • 打赏
  • 举报
回复
什么没人懂,你知道只有连接时候才是mysql?
b15365637 2019-12-31
  • 打赏
  • 举报
回复
没人懂吗??????????????
b15365637 2019-12-27
  • 打赏
  • 举报
回复
引用 11 楼 于小九 的回复:
[quote=引用 10 楼 b15365637的回复:][quote=引用 6 楼 于小九 的回复:]
没看出来你修改前后有什么不一样啊,这样试试看
	public function connect() {
$func = $this->config['pconnect'] == 1 ? 'mysqli_pconnect' : 'mysqli_connect';
  if(!$this->link = @$func($this->config['hostname'], $this->config['username'], $this->config['password'], 1)) {
$this->halt('Can not connect to MySQL server');
return false;
}

if($this->version() > '4.1') {
$charset = isset($this->config['charset']) ? $this->config['charset'] : '';
$serverset = $charset ? "character_set_connection='$charset',character_set_results='$charset',character_set_client=binary" : '';
$serverset .= $this->version() > '5.0.1' ? ((empty($serverset) ? '' : ',')." sql_mode='' ") : '';
$serverset && mysqli_query("SET $serverset", $this->link);
}

if($this->config['database'] && !@mysqli_select_db($this->config['database'], $this->link)) {
$this->halt('Cannot use database '.$this->config['database']);
return false;
}
$this->database = $this->config['database'];
return $this->link;
}


mysqli_connect(): (HY000/1044): Access denied for user 'root'@'localhost' to database '1' | olcms/libs/classes/mysql.class.php | 79


79行
 		if(!$this->link = @$func($this->config['hostname'], $this->config['username'], $this->config['password'], 1)) {
[/quote]
数据库不存在,你发上来的时候数据库名就是1,这边没有修改,可以检查一下程序配置使用的是哪一个数据库名称修改一下就行。
if(!$this->link = @$func($this->config['hostname'], $this->config['username'], $this->config['password'], '这里改为你程序使用到的数据库名称'))

[/quote]

不行这样修改后网站打开超时打不开了
 		if(!$this->link = @$func($this->config['hostname'], $this->config['username'], $this->config['password'],$this->config['database'])) {

于小九 2019-12-26
  • 打赏
  • 举报
回复
引用 10 楼 b15365637的回复:
[quote=引用 6 楼 于小九 的回复:]
没看出来你修改前后有什么不一样啊,这样试试看
	public function connect() {
$func = $this->config['pconnect'] == 1 ? 'mysqli_pconnect' : 'mysqli_connect';
  if(!$this->link = @$func($this->config['hostname'], $this->config['username'], $this->config['password'], 1)) {
$this->halt('Can not connect to MySQL server');
return false;
}

if($this->version() > '4.1') {
$charset = isset($this->config['charset']) ? $this->config['charset'] : '';
$serverset = $charset ? "character_set_connection='$charset',character_set_results='$charset',character_set_client=binary" : '';
$serverset .= $this->version() > '5.0.1' ? ((empty($serverset) ? '' : ',')." sql_mode='' ") : '';
$serverset && mysqli_query("SET $serverset", $this->link);
}

if($this->config['database'] && !@mysqli_select_db($this->config['database'], $this->link)) {
$this->halt('Cannot use database '.$this->config['database']);
return false;
}
$this->database = $this->config['database'];
return $this->link;
}


mysqli_connect(): (HY000/1044): Access denied for user 'root'@'localhost' to database '1' | olcms/libs/classes/mysql.class.php | 79


79行
 		if(!$this->link = @$func($this->config['hostname'], $this->config['username'], $this->config['password'], 1)) {
[/quote] 数据库不存在,你发上来的时候数据库名就是1,这边没有修改,可以检查一下程序配置使用的是哪一个数据库名称修改一下就行。
if(!$this->link = @$func($this->config['hostname'], $this->config['username'], $this->config['password'], '这里改为你程序使用到的数据库名称'))
b15365637 2019-12-26
  • 打赏
  • 举报
回复
引用 6 楼 于小九 的回复:
没看出来你修改前后有什么不一样啊,这样试试看
	public function connect() {
$func = $this->config['pconnect'] == 1 ? 'mysqli_pconnect' : 'mysqli_connect';
  if(!$this->link = @$func($this->config['hostname'], $this->config['username'], $this->config['password'], 1)) {
$this->halt('Can not connect to MySQL server');
return false;
}

if($this->version() > '4.1') {
$charset = isset($this->config['charset']) ? $this->config['charset'] : '';
$serverset = $charset ? "character_set_connection='$charset',character_set_results='$charset',character_set_client=binary" : '';
$serverset .= $this->version() > '5.0.1' ? ((empty($serverset) ? '' : ',')." sql_mode='' ") : '';
$serverset && mysqli_query("SET $serverset", $this->link);
}

if($this->config['database'] && !@mysqli_select_db($this->config['database'], $this->link)) {
$this->halt('Cannot use database '.$this->config['database']);
return false;
}
$this->database = $this->config['database'];
return $this->link;
}


mysqli_connect(): (HY000/1044): Access denied for user 'root'@'localhost' to database '1' | olcms/libs/classes/mysql.class.php | 79


79行
 		if(!$this->link = @$func($this->config['hostname'], $this->config['username'], $this->config['password'], 1)) {
pzzc18 2019-12-25
  • 打赏
  • 举报
回复
引用 4 楼 b15365637 的回复:
[quote=引用 3 楼 xuzuning 的回复:] mysql_select_db???这是 mysqli 吗?
该怎么改呢 大哥帮帮忙撒[/quote] mysqli_select_db
于小九 2019-12-24
  • 打赏
  • 举报
回复
没看出来你修改前后有什么不一样啊,这样试试看
	public function connect() {
		$func = $this->config['pconnect'] == 1 ? 'mysqli_pconnect' : 'mysqli_connect';
 		if(!$this->link = @$func($this->config['hostname'], $this->config['username'], $this->config['password'], 1)) {
			$this->halt('Can not connect to MySQL server');
			return false;
		}

		if($this->version() > '4.1') {
			$charset = isset($this->config['charset']) ? $this->config['charset'] : '';
			$serverset = $charset ? "character_set_connection='$charset',character_set_results='$charset',character_set_client=binary" : '';
			$serverset .= $this->version() > '5.0.1' ? ((empty($serverset) ? '' : ',')." sql_mode='' ") : '';
			$serverset && mysqli_query("SET $serverset", $this->link);		
		}

		if($this->config['database'] && !@mysqli_select_db($this->config['database'], $this->link)) {
			$this->halt('Cannot use database '.$this->config['database']);
			return false;
		}
		$this->database = $this->config['database'];
		return $this->link;
	}
b15365637 2019-12-24
  • 打赏
  • 举报
回复
有人吗???
b15365637 2019-12-23
  • 打赏
  • 举报
回复
引用 1 楼 廖展程 的回复:
他叫你改为mysqli连接。那你扩展开了吗

肯定开了的啊
b15365637 2019-12-23
  • 打赏
  • 举报
回复
引用 3 楼 xuzuning 的回复:
mysql_select_db???这是 mysqli 吗?

该怎么改呢 大哥帮帮忙撒
xuzuning 2019-12-23
  • 打赏
  • 举报
回复
mysql_select_db???这是 mysqli 吗?
廖展程 2019-12-22
  • 打赏
  • 举报
回复
他叫你改为mysqli连接。那你扩展开了吗

21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧