gpt4 book ai didi

php - 使用未定义的常量 DB_SERVER - 假定为 'DB_SERVER'

转载 作者:行者123 更新时间:2023-12-04 21:00:47 24 4
gpt4 key购买 nike

我有以下 php 代码:

$db_host = "localhost";
$db_user = "root";
$db_pass = "";
$db_name = "photos";

define(DB_SERVER,$db_host);
define(DB_USER,$db_user);
define(DB_PASS,$db_pass);
define(DB_NAME,$db_name);

我正在定义 DB_SERVER 以及您在上面看到的所有其他内容,但由于某种原因,我收到以下错误:

Notice: Use of undefined constant DB_SERVER - assumed 'DB_SERVER' in /Users/ahoura/Sites/photos/include/config.php on line 34 Notice: Use of undefined constant DB_USER - assumed 'DB_USER' in /Users/ahoura/Sites/photos/include/config.php on line 35 Notice: Use of undefined constant DB_PASS - assumed 'DB_PASS' in /Users/ahoura/Sites/photos/include/config.php on line 36 Notice: Use of undefined constant DB_NAME - assumed 'DB_NAME' in /Users/ahoura/Sites/photos/include/config.php on line 37

我做错了什么!?!?!

最佳答案

您需要在 define() 中引用新常量的名称

define('DB_SERVER',$db_host);
define('DB_USER',$db_user);
define('DB_PASS',$db_pass);
define('DB_NAME',$db_name);

该通知表明 PHP 实际上确实将它们视为带引号的字符串,因为它无法找到具有这些名称的现有常量,但这是不值得依赖的做法。 define() 将字符串作为要定义的常量的名称及其预期值。

关于php - 使用未定义的常量 DB_SERVER - 假定为 'DB_SERVER',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8273336/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com