解析错误:语法错误,第9行的C:\ wamp64 \ www \ bluepeatshop \ db_connect.php中出现意外的':'

时间:2018-08-25 16:00:37

标签: php mysql apache mysqli

db_connect.php

<?php
class DB_Connect {
    private $conn;

    public function connect()
    {
        require_once 'config.php';
        $this->conn = new mysqli_connect(host:DB_HOST,username:DB_USER,passwd:DB_PASSWORD,dbname:DB_DATABASE);
        return $this->conn;
    }
}
?>

config.php

<?php
define(DB_HOST, "localhost");
define(DB_USER, "root");
define(DB_PASSWORD, "");
define(DB_DATABASE, "bluepeatshop");
?>

错误是:

Parse error: syntax error, unexpected ':' in C:\wamp64\www\bluepeatshop\db_connect.php
        on line 9

1 个答案:

答案 0 :(得分:0)

您的常量用法不正确,请尝试如下更改数据库连接字符串,

<?php
class DB_Connect {
    private $conn;

    public function connect()
    {
    require_once 'config.php';
    $this->conn = new mysqli_connect(DB_HOST,DB_USER,DB_PASSWORD,DB_DATABASE);
    return $this->conn;
    }
}
?>