微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

php – 已弃用函数的替换mysql_connect

参见英文答案 > mysqli or PDO – what are the pros and cons? [closed]                                    13个
所以我已经设置了这个Amazon Web Service数据库

我正在为一个我计划使用它的应用程序编写一个旧教程.

我注意到MysqL_connect在我查找时已经弃用了.

我可以用什么作为替代品?如何连接到我的亚马逊数据库

<?
MysqL_connect("localhost", "username", "password") or die ("Can't connect to database server");
MysqL_select_db("videoRecorderDemo") or die ("Can't select database");
MysqL_query("SET NAMES 'utf8'");
?>

我收到此错误

Warning: MysqL_connect() [function.mysql-connect]: Access denied for user 'username'@'192.168.1.1' (using password: YES) in /www/zxq.net/r/e/d/red5vptest/htdocs/utility/db.PHP on line 2
Can't connect to database server

无论我使用什么凭据.
亚马逊的代码示例显示您以完全不同的方式连接也无济于事.

解决方法:

The documentation for PHP says

This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the 07001 or 07002 extension should be used.

$MysqLi = new MysqLi('localhost', 'my_user', 'my_password', 'my_db');

/*
 * This is the "official" OO way to do it,
 * BUT $connect_error was broken until PHP 5.2.9 and 5.3.0.
 */
if ($MysqLi->connect_error) {
    die('Connect Error (' . $MysqLi->connect_errno . ') '
            . $MysqLi->connect_error);
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐