【发布时间】:2017-05-14 05:38:16
【问题描述】:
我有以下 php 代码将我的数据库与 mysql_connect() 连接起来,但我不断收到以下警告:
不推荐使用:mysql_connect():不推荐使用 mysql 扩展,并且 将来会被移除:使用mysqli或PDO代替.....
更新此连接的正确方法是什么,这样我以后就不会遇到任何问题?
<?php
//CREATED BY ...
/*
1: "die()" will exit the script and show an error statement if something goes wrong
2: A "mysql_connect()" error usually means your username/password are wrong
3. A "mysql_select_db()" error usually means the database does not exist
*/
//Place db host name. Sometimes "localhost" but
//sometimes looks like this: >> ???mysql??.someserver.net
$db_host = "localhost";
//Place the username for the MySQL database here
$db_username = "...";
//Place the password here:
$db_pass = "...";
//Place the name for the MyS
$db_name = "...";
//Run the connection right here!
mysqli_connect("$db_host","$db_username","$db_pass") or die ("could not connect");
mysql_select_db("$db_name") or die("no databases");
?>
编辑:突出显示错误一目了然。
【问题讨论】:
-
使用
mysqli或PDO重新编码您的脚本。 -
所有 mysql_* 函数已弃用。您需要在您的代码中替换所有,而不仅仅是少数。
标签: php mysql database deprecated mysql-connect