我已经阅读了很多这方面的帖子,似乎没有任何共识.我正在为Web应用程序编写一个开源通用安装程序,我需要确认一个成功的PDO连接.它需要测试PDO连接,然后它将编写实际的config/init文件.文件编写部分工作正常,但我似乎无法得到PDO真正连接的具体验证.如果表单为空,它表示已连接,如果表单中的某些信息正确,则表示已连接.如何清楚地表明pdo凭据是否正确?我会给你一个(精简版)我正在做的事情.
表格:
<H2>Please fill in your database credentials</H2>
<form class="form" action="" method="post">
<label for="dbh">Database Host
<input class="form-control" type="text" name="dbh" value="<?php if (!empty($_POST['dbh'])){ print $_POST['dbh']; } ?>"></label><br><br>
<label for="dbu">Database User
<input class="form-control" type="text" name="dbu" value="<?php if (!empty($_POST['dbu'])){ print $_POST['dbu']; } ?>"></label><br><br>
<label for="dbp">Database Password
<input class="form-control" type="text" name="dbp" value="<?php if (!empty($_POST['dbp'])){ print $_POST['dbp']; } ?>"></label><br><br>
<label for="dbn">Database Name
<input class="form-control" type="text" name="dbn" value="<?php if (!empty($_POST['dbn'])){ print $_POST['dbn']; } ?>"></label><br><br>
Run Code Online (Sandbox Code Playgroud)
PHP
<?php
if (!empty($_POST)) {
$dbh=$_POST['dbh']; //db host
$dbu=$_POST['dbu']; //db username
$dbp=$_POST['dbp']; …Run Code Online (Sandbox Code Playgroud)