Home > Article > Backend Development > Why can't PHP connect to the database?
<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
<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