Parse error: syntax error, unexpected T_PAAMAYIM_NEKUDOTAYIM in Z:\home\web.together.org\www\core\controllers\database.php on line 11
class Database {
public $isConnect;
public $db;
public function __construct ($dbname, $user = "root", $password = "", $host = "localhost", $type = "mysql", $charset = "utf8", $options = array()) {
$this->isConnect = true;
try {
$this->db = new PDO("{$type}:host={$host};dbname={$dbname};charset={$charset};", $user, $password, $options);
$this->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$this->db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::PDO::FETCH_ASSOC); //вот эта строка 11
} catch (PDOException $e) {
throw new Exception($e->getMessage());
}
}
public function Disconnect () {
$this->db = NULL;
$this->isConnect = false;
}
public function insertRow ($query, $params = array()) {
try {
$insert = $this->db->prepare($query);
$insert->execute($params);
return true;
} catch (PDOException $e) {
throw new Exception($e->getMessage());
}
}
public function getRow ($query, $params = array()) {
try {
$get = $this->db->prepare($query);
$get->execute($params);
return $get->fetch();
} catch (PDOException $e) {
throw new Exception($e->getMessage());
}
}
public function getRows ($query, $params = array()) {
try {
$get = $this->db->prepare($query);
$get->execute($params);
return $get->fetchAll();
} catch (PDOException $e) {
throw new Exception($e->getMessage());
}
}
public function updateRow ($query, $params = array()) {
$this->insertRow($query, $params);
}
public function deleteRow ($query, $params = array()) {
$this->insertRow($query, $params);
}
}
class Database {
public $db;
public function __construct ($dbname, $user = "root", $password = "", $host = "localhost", $type = "mysql", $charset = "utf8", $options = array())
{
$default_options = [
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
PDO::ATTR_EMULATE_PREPARES => false,
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
];
$options = array_replace($default_options, $options);
try {
$this->db = new PDO("{$type}:host={$host};dbname={$dbname};charset={$charset};", $user, $password, $options);
} catch (PDOException $e) {
throw new \PDOException($e->getMessage(), (int)$e->getCode());
}
}
public function disconnect () {
$this->db = NULL;
}
public function query ($query, $params = array()) {
$stmt = $this->db->prepare($query);
$stmt->execute($params);
return $stmt;
}
public function getRow ($query, $params = array(), $fetchMode = PDO::PDO_FETCH_ASSOC) {
return $this->query->fetch($fetchMode);
}
public function getRows ($query, $params = array(), $fetchMode = PDO::PDO_FETCH_ASSOC) {
return $this->query->fetchAll($fetchMode);
}
}