<?php
class Database{
private $hostdb="localhost";
private $userdb = "root";
private $passdb = "";
private $namedb = "database"
public $pdo;
public function __construct(){
if(!isset($this->pdo)) {
try{
$link = new PDO("mysql:host=".$this->hostdb.";dbname=".$this->namedb, $this->userdb, $this->passdb);
$link->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$link->exec("SET CHARACTER SET utf8");
$this->pdo = $link;
}catch(PDOException $e){
die("failed to connect with database".$e->getMessage());
}
}
}
}
?>`
解析错误:语法错误,意外的“ public”(T_PUBLIC),期望为“,”或“;”在第7行的C:\ xampp \ htdocs \ lr \ lib \ Database.php中
答案 0 :(得分:-1)
缺少分号:
private $namedb = "database" ; // <--