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);
}

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...