解析错误:语法错误,意外'。''(T_DNUMBER),期待','或';'在第6行的C:\ xampp \ htdocs \ myblog \ classes \ Database.php中

时间:2018-02-27 13:03:12

标签: php mysql pdo

<?php


class Database {

    private $host = 127.0.1;
    private $user = 'root';
    private $pass= '';
    private $dbname= 'myblog';

    private $dbh;
    private $error;
    private $stmt;


    public function __construct()
    {
        // set the DSN
        $dsn ='mysql:host='. $this->host . ' ;dbname= '. $this->dbname;
        // set options
        $options= array(
        PDO::ATTR_PERSISTENT  =>true,
        PDO::ATTR_ERRMODE      =>PDO::ERRMODE_EXCEPTION
        );
        // create new PDO
        try {
        $this->dbh= new PDO($dsn, $this->user, $this->pass, $options);

        }
        catch (PDOException $e){
           echo $e->getMessages();
            // echo "database problem";
        }
    }
}


?>

1 个答案:

答案 0 :(得分:0)

private $host应为字符串

private $host = "127.0.0.1";