我从数据库中获取信息时遇到了一些问题。 在我尝试使用与db一起工作的方法的那一刻,我得到了超出最大执行时间的错误,这是我之前没有得到的。 这是我的数据库代码。我在第68行得到错误,这是execute()方法
<?php
define("DB_HOST", "localhost");
define("DB_USER", "root");
define("DB_PASS", "ff");
define("DB_NAME", "photo_gallery");
class Database{
private $host = DB_HOST;
private $user = DB_USER;
private $pass = DB_PASS;
private $dbname = DB_NAME;
public $query;
public $result;
private $con;
private $error;
public function __construct(){
// Set DSN
$dsn = 'mysql:host=' . $this->host . ';dbname=' . $this->dbname;
// Set options
$options = array(
PDO::ATTR_PERSISTENT => true,
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
);
// Create a new PDO instanace
try{
$this->con = new PDO($dsn, $this->user, $this->pass, $options);
}
// Catch any errors
catch(PDOException $e){
$this->error = $e->getMessage();
}
}
public function query($query){
$this->result = $this->con->prepare($query);
}
public function bind($param, $value, $type = null){
if (is_null($type)) {
switch (true) {
case is_int($value):
$type = PDO::PARAM_INT;
break;
case is_bool($value):
$type = PDO::PARAM_BOOL;
break;
case is_null($value):
$type = PDO::PARAM_NULL;
break;
default:
$type = PDO::PARAM_STR;
}
}
$this->result->bindParam($param,$value,$type);
}
public function execute()
{
return $this->result->execute();
}
public function rowCount()
{
return $this->result->rowCount();
}
public function fetch_assoc($result){
$this->execute();
return $this->result->fetch(PDO::FETCH_ASSOC);
}
}
$db = new Database();
?>