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

PHP connection mysql database problem

WBOY
Release: 2016-08-04 09:22:07
Original
1112 people have browsed it

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>
Copy after login
Copy after login

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>
Copy after login
Copy after login

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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template