Home > Backend Development > PHP Tutorial > Why can't PHP connect to the database?

Why can't PHP connect to the database?

WBOY
Release: 2023-03-03 09:38:01
Original
1272 people have browsed it

<code>$dbc = @mysqli_connect('localhost','root','lalala');
if(@mysqli_select_db("one",$dbc)){
    print 'YES!';
}else{
    print 'NO!';
    mysqli_error($dbc);
    exit();
}</code>
Copy after login
Copy after login

That’s it for a few lines of code. I can connect to mysql, but I can't connect to the database and there is no error message.
Using wamp’s phpmyadmin

Reply content:

<code>$dbc = @mysqli_connect('localhost','root','lalala');
if(@mysqli_select_db("one",$dbc)){
    print 'YES!';
}else{
    print 'NO!';
    mysqli_error($dbc);
    exit();
}</code>
Copy after login
Copy after login

That’s it for a few lines of code. I can connect to mysql, but I can't connect to the database and there is no error message.
Using wamp’s phpmyadmin

Function: mysqli_select_db(connection,dbname)

You have reversed the parameters.

You can check the manual. Mysql and mysqli are different.
bool mysqli_select_db (mysqli $link, string $dbname);
bool mysql_select_db (string $database_name [, resource $ link_identifier])
It should be said that it is just the opposite. Remember to put it when testing Turn on debug.

You try to connect to the database using the command line
mysql -u -p

Related labels:
php
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