置换pcated德$ P $函数的mysql_connect [英] Replacement for deprecated function mysql_connect

查看:107
本文介绍了置换pcated德$ P $函数的mysql_connect的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有这样的亚马逊Web服务数据库中所有设置了

我工作过的老教程,我正打算使用它的应用程序。

我注意到的mysql_connect是德precate,当我看着它。

我可以作为替代使用?我怎样才能连接到我的亚马逊的数据库?

 &LT ;?
的mysql_connect(localhost,则用户名,密码)或死亡(无法连接到数据库服务器);
mysql_select_db(videoRecorderDemo)或死亡(无法选择数据库);
请求mysql_query(SET NAMES'UTF8');
?>
 

我得到这个错误:

 警告:mysql_connect()函数[function.mysql连接]:是/ www / ZXQ:拒绝访问用户username'@'192.168.1.1(是使用密码)。净/ R / E / D / red5vptest / htdocs中/工具/在线2 db.php中
无法连接到数据库服务器
 

不管我用什么凭据。 它也没有帮助,亚马逊的code样本显示在连接在一个完全不同的方式。

解决方案

的文档PHP说:

  

此扩展pcated作为PHP 5.5.0中去$ P $,并且将在未来被删除。相反,的MySQLi 或的 PDO_MYSQL 扩展程序应该被使用。

  $库MySQLi =新库MySQLi(本地主机,my_user','MY_PASSWORD','MY_DB');

/ *
 *这是官方的面向对象的方式来做到这一点,
 *但$ connect_error被打破,直到PHP 5.2.9和5.3.0。
 * /
如果($ mysqli-> connect_error){
    死亡(连接错误('$ mysqli-> connect_errno')。
            。 $ mysqli-> connect_error);
}
 

So I have this Amazon Web Service database all set up

I'm working off an old tutorial for an application that I'm planning on using it with.

I noticed that mysql_connect was deprecate when I looked it up.

What can I use as an alternative? How can I connect to my amazon database?

<?
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'");
?>

I get this error:

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

No matter what credentials I use. It also doesn't help that Amazon's code samples show you connecting in an entirely different way.

解决方案

The documentation for PHP says

This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQL 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);
}

这篇关于置换pcated德$ P $函数的mysql_connect的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆