解决The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead

在php5.3环境下,写了一个脚本,放到php5.6环境中直接错误:Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead,意思是说要用mysqli或者PDO来替代mysql_*,mysql_*将在未来弃用。

解决方法1:

<?php
$connect = mysql_connect('localhost', 'user', 'password');
mysql_select_db('dbname', $connect);
//换用mysqi
<?php
$link = mysqli_connect('localhost', 'user', 'password', 'dbname');
<?php
mysql_query('select * from tablename', $connect);
// 换用mysqli
mysqli_query($connect, 'select * from tablename');

解决方法2:

在php程序代码里面(或在服务器php配置文件中)设置报警级别

<?php
error_reporting(E_ALL ^ E_DEPRECATED);

Deprecated的问题到此已解决。

评论

评论正在提交中...请稍后
评论提交成功...