Home  >  Article  >  Backend Development  >  PHP connection mysql database problem

PHP connection mysql database problem

WBOY
WBOYOriginal
2016-08-04 09:22:071086browse

Database connection code:

<code>$server="localhost";
$username="root";
$password="";
$database="library";

$conn=mysqli_connect($server,$username,$password);
if (!$conn) {
    die("mysqli_connect failed".mysql_error());
}
$db_selected = mysql_select_db($database,$conn);
if (!$db_selected) {
    die("select db error:".mysql_error());
}</code>

The connection returns a prompt: select db error:
Why is this? Navicat can be used to connect to the library database.

Reply content:

Database connection code:

<code>$server="localhost";
$username="root";
$password="";
$database="library";

$conn=mysqli_connect($server,$username,$password);
if (!$conn) {
    die("mysqli_connect failed".mysql_error());
}
$db_selected = mysql_select_db($database,$conn);
if (!$db_selected) {
    die("select db error:".mysql_error());
}</code>

The connection returns a prompt: select db error:
Why is this? Navicat can be used to connect to the library database.

$db_selected = mysql_select_db($database,$conn);

Change to $db_selected = mysqli_select_db($database,$conn);

Yes, you wrote mysqli as mysql

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn