我尝试通过循环来定义常量值,但是它出错了:
Notice: Use of undefined constant XXXXX - assumed 'XXXXX' in XX on line XX
这是代码:
$q = "SELECT `Key`, `Value` FROM appconfig";
//I skip the line to read from database
while($fetch = mysqli_fetch_array($r)) {
define("'" . $fetch["Key"] . "'", $fetch["Value"]);
//I try to echo $fetch["Key"] and $fetch["Value"] and it returns value
}
代码有问题吗?我试图手动定义它,它的工作原理。
答案 0 :(得分:3)
不要使用引号,你不需要它们:
define($fetch["Key"], $fetch["Value"]);