1

我尝试通过循环定义常量值,但出现错误:

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
}

代码有问题吗?我试图手动定义它并且它有效。

4

1 回答 1

3

不要使用引号,你不需要它们:

define($fetch["Key"], $fetch["Value"]);
于 2013-05-23T02:50:11.667 回答