连接php.ini后连接到Mysql时出错

时间:2014-11-14 07:32:15

标签: php mysql connect

美好的一天。请告诉我如何修复连接到Mysql的错误?

Warning: mysqli_select_db() expects exactly 2 parameters, 1 given in /home/user/db.php on line 7

Warning: mysqli_error() expects parameter 1 to be mysqli, string given in /home/user/db.php on line 7

脚本看起来像这样

mysqli_connect("localhost", "user", "pass") or die (mysqli_error ());

mysqli_select_db("db_name") or die(mysqli_error());

如果不连接php.ini,一切正常,如果我连接(它现在为空),有一个错误。在服务器上的PHP 5.5,共享主机。

2 个答案:

答案 0 :(得分:1)

连接也必须在mysqli_select_db()

的参数内输入
$con = mysqli_connect("localhost", "user", "pass") or die(mysqli_connect_error());
mysqli_select_db($con, "db_name") or die(mysqli_error($con));

参考:http://php.net/manual/en/mysqli.select-db.php

答案 1 :(得分:0)

尝试这样的事情:

$conn = mysqli_connect("localhost", "user", "pass") or die (mysqli_error ());
mysqli_select_db("db_name", $conn) or die(mysqli_error());