Reputation: 59
this is my db file
config.php
define(HOST_NAME, "localhost");
define(USER, "root");
define(PASSWORD, "");
define(DATABASE, "xxx");
now i wanted to call these constants in my db file
db.php
class Database {
function db_connect() {
$conn =mysql_connect(HOST_NAME, USER, PASSWORD);
}
}
$obj_db = new Database();
$obj_db->db_connect();
but these constants are not coming in mysql_connect and its giving error
Unknown MySQL server host 'HOST_NAME' (11001)
please help thanks
Upvotes: 0
Views: 74
Reputation: 160833
You should have config.php
been included by include 'config.php';
.
There are 4 ways of doing this:
include 'config.php';
include_once 'config.php';
require 'config.php';
require_once 'config.php';
PS: You need the quotes when define the constant.
define('HOST_NAME', "localhost");
define('USER', "root");
define('PASSWORD', "");
define('DATABASE', "xxx");
Upvotes: 2