解析错误:语法错误,c:\wamp64\www\bluepeatshop\db\u connect.php第9行出现意外“:”

smtd7mpg  于 2021-06-20  发布在  Mysql
关注(0)|答案(1)|浏览(259)

数据库连接.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;
    }
}
?>

配置.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
yduiuuwa

yduiuuwa1#

您的固定用法不正确,请尝试按以下方式更改您的db connect字符串,

<?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;
    }
}
?>

相关问题