【发布时间】:2019-03-28 18:39:56
【问题描述】:
或者:“以这种方式更改 php/mysql 数据库会创建不安全的连接吗?”
我正在考虑自动化我的实时/测试数据库。我对mysql有点天真,所以我想我最好在这里问这个问题:
在以下 php/mysql 场景中会产生什么后果和/或安全问题?
// set up the standard database
// Connection codes:
$host="localhost";
$user="imauser";
$password="imapassword";
$dbname="liveDB";
$cxn = mysqli_connect ($host,$user,$password,$dbname)
or die ("Couldn't connect to the server.");
// check if $testMode is active, and reset $cxn with a new (test) $dbname:
if($testMode == TRUE){
$dbname="testDB"; // test database
// reset the cxn:
$cxn = mysqli_connect ($host,$user,$password,$dbname)
or die ("Couldn't connect to the server.");
}
这将允许我在代码的更高级别切换 $testMode。 $cxn 的简单覆盖是否有效,或者我是否有一个打开且活动的 mysqli_connect 连接挂起?
【问题讨论】:
标签: php mysql security database-connection