更新时间:2023-01-05 07:56:41
是的!您需要删除任何HTML在connect_db.php文件。我建议存储变量在该文件中检查,如果你的连接成功。例如:
Yep! You need to remove any HTML in the connect_db.php file. I recommend storing a variable in that file checking if your connection was successful. For example:
connect_db.php
$isConnected = false;
$dbError = "";
if ($dbc=mysqli_connect('localhost','*****','*****','ff') {
$isConnected = true;
} else {
$dbError = mysqli_connect_error();
}
等文件
require("connect_db.php");
if($isConnected) {
//DO ALL YO STUFF!!
} else {
//HANDLE THE ERROR AS YOU LIKE, LIKE PRINTING IT OUT
echo $dbError;
}
这样做可以让你如果无法连接,所以你可以得体的处理失败的连接处理数据库逻辑文件。
Doing this will allow you to handle the DB logic in your files if it fails to connect so you may handle failed connections gracefully.