Home >Backend Development >PHP Problem >What to do if database selection fails in php
Solution to failed database selection in php: 1. Check mysql_select_db and mysqli_select_db; 2. Modify the order of incoming parameters of the two connection methods.
The operating environment of this article: Windows 7 system, PHP version 7.1, Dell G3 computer.
What should I do if the database selection fails in php?
"Failed to select database" occurs when PHP connects to the database?
When PHP connects to the database:
There is no problem connecting to the database with mysqli_connect, but there is always an error when using mysqli_select_db ! Puzzled.
After careful observation of mysql_select_db and mysqli_select_db, I found that
The incoming parameters of mysql_select_db are ($databaseName,$query);
The incoming parameters of mysqli_select_db The parameters are ($query,$databaseName);
At this point, it turns out that the order of the parameters passed in the two connection methods is not the same, so the selection failed.
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of What to do if database selection fails in php. For more information, please follow other related articles on the PHP Chinese website!