Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/56.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 如何调用db文件中的常量?_Php_Mysql - Fatal编程技术网

Php 如何调用db文件中的常量?

Php 如何调用db文件中的常量?,php,mysql,Php,Mysql,这是我的数据库文件 config.php define(HOST_NAME, "localhost"); define(USER, "root"); define(PASSWORD, ""); define(DATABASE, "xxx"); db.php class Database { function db_connect() { $conn =mysql_connect(HOST_NAME, USER, PASSWORD); } } $obj_db = new Database();

这是我的数据库文件

config.php

define(HOST_NAME, "localhost");
define(USER, "root");
define(PASSWORD, "");
define(DATABASE, "xxx");
db.php
class Database {
function db_connect() {
$conn =mysql_connect(HOST_NAME, USER, PASSWORD);
}
}
$obj_db = new Database();
$obj_db->db_connect();
现在我想在我的db文件中调用这些常量

config.php

define(HOST_NAME, "localhost");
define(USER, "root");
define(PASSWORD, "");
define(DATABASE, "xxx");
db.php
class Database {
function db_connect() {
$conn =mysql_connect(HOST_NAME, USER, PASSWORD);
}
}
$obj_db = new Database();
$obj_db->db_connect();
但是mysql_connect及其给定错误中没有这些常量

 Unknown MySQL server host 'HOST_NAME' (11001)
请帮忙
谢谢

你应该已经被
include'config.php'收录了
config.php

有4种方法可以做到这一点:

include 'config.php';
include_once 'config.php';
require 'config.php';
require_once 'config.php';
PS:定义常量时需要引号

define('HOST_NAME', "localhost");
define('USER', "root");
define('PASSWORD', "");
define('DATABASE', "xxx");

include'config.php'应该包含
config.php

有4种方法可以做到这一点:

include 'config.php';
include_once 'config.php';
require 'config.php';
require_once 'config.php';
PS:定义常量时需要引号

define('HOST_NAME', "localhost");
define('USER', "root");
define('PASSWORD', "");
define('DATABASE', "xxx");

带有


文件已包含,但变量未在
mysql\u connect()中赋值文件已包含,但变量未在
mysql_connect()中赋值文件已包含,但变量未在
mysql_connect()中赋值
@Sparkx您的define-need-quotes.file已包含在内,但变量未在
mysql_-connect()中赋值@Sparkx您需要定义报价。