Home > Article > Backend Development > PHP connection mysql database problem
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.
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