本文实例讲述了php提示 deprecated: mysql_connect(): the mysql extension is deprecated的解决方法,在php程序开发中常会遇到这类问题。分享给大家供大家参考,具体的解决方法如下:
将下面代码改为mysqli或PDO即可。
function connectit () {
global $CFG;
mysql_connect($CFG['db_host'], $CFG['db_user'], $CFG['db_pass']) or die(mysql_error());
mysql_select_db($CFG['db_name']);
}
PDO:
$dbh = new PDO('mysql:host=localhost;dbname=test', $user, $pass);
MYSQLI:
$link = mysqli_connect(
'localhost', /* The host to connect to 连接MySQL地址 */
'user', /* The user to connect as 连接MySQL用户名 */
'password', /* The password to use 连接MySQL密码 */
'world'); /* The default database to query 连接数据库名称*/
if (!$link) {
printf("Can't connect to MySQL Server. Errorcode: %s ", mysqli_connect_error());
exit;
}
希望本文所述对大家的PHP程序设计有所帮助。
立即学习“PHP免费学习笔记(深入)”;
参考答案我听不见彩虹出现的声音,我听不见太阳落下的声音.
在php最上面写error_reporting(E_ALL & ~E_DEPRECATED);忽略错误
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号