gpt4 book ai didi

php - 使用未定义的常量项目 - 假定为 'project'(这将在未来的 PHP 版本中引发错误)

转载 作者:行者123 更新时间:2023-11-29 02:39:54 25 4
gpt4 key购买 nike

我是 PHP 新手,不断收到上述错误。

下面是我的代码

<?php
/* Database credentials. Assuming you are running MySQL
server with default setting (user 'root' with no password) */
define('DB_SERVER', 'localhost');
define('DB_USERNAME', 'root');
define('DB_PASSWORD', '');
define('DB_NAME', 'project');

/* Attempt to connect to MySQL database */
$link = mysqli_connect(DB_SERVER, DB_USERNAME, DB_PASSWORD, project);

// Check connection
if($link === false){
die("ERROR: Could not connect. " . mysqli_connect_error());
}
?>

最佳答案

改为这样做。常量在左边定义,值在右边。您正在尝试按值调用它

<?php
/* Database credentials. Assuming you are running MySQL
server with default setting (user 'root' with no password) */
define('DB_SERVER', 'localhost');
define('DB_USERNAME', 'root');
define('DB_PASSWORD', '');
define('DB_NAME', 'project');

/* Attempt to connect to MySQL database */
$link = mysqli_connect(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_NAME);

// Check connection
if($link === false){
die("ERROR: Could not connect. " . mysqli_connect_error());
}
?>

关于php - 使用未定义的常量项目 - 假定为 'project'(这将在未来的 PHP 版本中引发错误),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54895800/

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