通过循环定义常量

时间:2013-05-23 02:47:44

标签: php constants

我尝试通过循环来定义常量值,但是它出错了:

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
}

代码有问题吗?我试图手动定义它,它的工作原理。

1 个答案:

答案 0 :(得分:3)

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

define($fetch["Key"], $fetch["Value"]);