Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
奇怪的php require/include错误_Php_Mysql - Fatal编程技术网

奇怪的php require/include错误

奇怪的php require/include错误,php,mysql,Php,Mysql,我是一个比较新的发展,但确实知道一些东西 我正在做一个关于PHP的教程,它超越了Lynda的基础知识,并试图创建数据库类 require_once("config.php");//line 13 class MySQLDatabase{ //code that is not important for this issue } 在课堂上写完所有内容后,我试着看看是否建立了联系 require_once("../includes/database.php"); if(isset($dat

我是一个比较新的发展,但确实知道一些东西

我正在做一个关于PHP的教程,它超越了Lynda的基础知识,并试图创建数据库类

require_once("config.php");//line 13

class MySQLDatabase{
   //code that is not important for this issue
}
在课堂上写完所有内容后,我试着看看是否建立了联系

require_once("../includes/database.php");
if(isset($database)) {
    echo "true<br />";
}else {
    echo "false<br />";
}
这使我在页面上出现以下错误:

 Notice: Use of undefined constant DB_SERVER - assumed 'DB_SERVER' in       E:\ProgramFiles\xampp\htdocs\photo_gallery\includes\database.php on line 13

 Notice: Use of undefined constant DB_USER - assumed 'DB_USER' in E:\ProgramFiles\xampp\htdocs\photo_gallery\includes\database.php on line 13

 Notice: Use of undefined constant DB_PASS - assumed 'DB_PASS' in      E:\ProgramFiles\xampp\htdocs\photo_gallery\includes\database.php on line 13
 Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in E:\ProgramFiles\xampp\htdocs\photo_gallery\includes\database.php on line 13

 Warning: mysql_connect(): php_network_getaddresses: getaddrinfo failed: No such host is known. in E:\ProgramFiles\xampp\htdocs\photo_gallery\includes\database.php on line 13

 Warning: mysql_connect(): php_network_getaddresses: getaddrinfo failed: No such host is known. in E:\ProgramFiles\xampp\htdocs\photo_gallery\includes\database.php on line 13
数据库连接失败:php\u network\u getaddresses:getaddrinfo失败:不知道这样的主机

如果我使用(下面的代码)而不是require/require\u once/include/include\u once部分,它就工作了

define("DB_SERVER", "localhost");
define("DB_USER", "gallery");
define("DB_PASS", "123465");
define("DB_NAME", "photo_gallery");
这不是我第一次使用require/include…但是我真的很困惑为什么这个方法不起作用:-/ (我将在完成DB类后将所有内容更改为mysqli,因为它是教程。不,我没有访问练习文件的权限)


(很抱歉发了这么长的帖子)

听起来像是在config.php中定义常量时遗漏了引号

wrong:
define(DB_SERVER, "localhost");
right:
define("DB_SERVER", "localhost");

仔细检查一下,或者在config.php中发布相关部分:)

尝试用以下方式定义常量

defined('DB_SERVER') ? null : define("DB_SERVER", "localhost");
defined('DB_USER')   ? null : define("DB_USER", "gallery");
defined('DB_PASS')   ? null : define("DB_PASS", "123456");
defined('DB_NAME')   ? null : define("DB_NAME", "photo_gallery");
要删除
注意事项:使用未定义的常量DB_SERVER
注意事项


或者我们缺少了什么,或者您的mysql数据库关闭了?

config.php中可能存在一些问题。在config.php中,您似乎没有像在示例中那样定义常量。正如它所说的,config.php中的常量在其定义中似乎缺少大括号。将coinfig.php添加到问题中(只需将login、pass和host替换为空格),实际上是使用了
mysql\u connect()
中的常量引发了错误,因为它们从一开始就没有定义过。虽然这是一个正确的建议,但它不可能是问题的原因。通知中的消息本身表示,如果尚未定义,
DB\u服务器
将被视为
“DB\u服务器”
。确定。。。修正了它,但在某种程度上我不认为它会做任何事情,因为它听起来有点荒谬。我刚刚将文件从“config.php”重命名为“conf.php”。。。我的印象是,它会以某种方式与来自xampp的同名文件冲突。我也用user1912855“声明的方式改变了我定义它们的方式(但它也以旧的方式工作)。我没想到它会与其他文件冲突,看到我是如何专门为我的includes文件夹提供路径的…感谢大家的回复!