或者:“将更改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连接?