<?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";
}
}
}
?>
答案 0 :(得分:0)
private $host
应为字符串
private $host = "127.0.0.1";