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

Why can't PHP connect to the database?

WBOY
WBOYOriginal
2016-12-05 13:44:181244browse

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

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>

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

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