douluchuo0801
2015-09-15 01:58
浏览 81
已采纳

使用未定义的常量和mysqli_connect():[重复]

This question already has an answer here:

I don't know why I'm getting this error. I'm just following what tutorial say. How do I fix this?

<?php

define ("HOST_NAME", "localhost");
define ("HOST_USER", "root");
define ("HOST_PASSWORD", "");
define ("DB_NAME", "db_user");
?>

And actual code

<?php 
require_once("config.php");

class MySQLDatabase{

private $connection;

function __construct(){
    $this->open_connection();
}

public function open_connection(){
    $this->connection = mysqli_connect(HOST_NAME,HOST_USER,HOST_PASSWORD,DB_NAME);
    if(mysqli_connect_errno()){
      die("Database connection failed" .
           mysqli_connect_error() .   
             " ( " . mysqli_connect_errno . ")"
      );
    }

}

Errors

Notice: Use of undefined constant HOST_NAME - assumed 'HOST_NAME' in C:\xampp\htdocs\first-project\includes\database.php on line 13

Notice: Use of undefined constant HOST_USER - assumed 'HOST_USER' in C:\xampp\htdocs\first-project\includes\database.php on line 13

Notice: Use of undefined constant HOST_PASSWORD - assumed 'HOST_PASSWORD' in C:\xampp\htdocs\first-project\includes\database.php on line 13

Notice: Use of undefined constant DB_NAME - assumed 'DB_NAME' in C:\xampp\htdocs\first-project\includes\database.php on line 13

Warning: mysqli_connect(): php_network_getaddresses: getaddrinfo failed: No such host is known. in C:\xampp\htdocs\first-project\includes\database.php on line 13

Warning: mysqli_connect(): (HY000/2002): php_network_getaddresses: getaddrinfo failed: No such host is known. in C:\xampp\htdocs\first-project\includes\database.php on line 13

Notice: Use of undefined constant mysqli_connect_errno - assumed 'mysqli_connect_errno' in C:\xampp\htdocs\first-project\includes\database.php on line 17 Database connection failedphp_network_getaddresses: getaddrinfo failed: No such host is known. ( mysqli_connect_errno)

</div>

1条回答 默认 最新

相关推荐 更多相似问题