1
0
Fork 0
mirror of https://github.com/Alamantus/Lexiconga.git synced 2025-08-11 16:21:14 +02:00
Lexiconga/public/api/Db.php

35 lines
921 B
PHP
Raw Normal View History

2017-12-24 12:00:45 -07:00
<?php
class Db {
private $dbh;
2018-06-17 14:52:58 -06:00
public $last_error_info;
function __construct() {
2017-12-24 12:00:45 -07:00
$this->dbh = new PDO('mysql:host=localhost;dbname=lexiconga;charset=utf8', 'root', 'password');
$this->dbh->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
2018-06-17 14:52:58 -06:00
$this->last_error_info = null;
2017-12-24 12:00:45 -07:00
}
public function execute ($query, $params = array()) {
$stmt = $this->dbh->prepare($query);
2018-06-17 14:52:58 -06:00
if ($stmt->execute($params)) {
$this->last_error_info = null;
return true;
}
$this->last_error_info = $stmt->errorInfo();
return false;
}
2017-12-24 12:00:45 -07:00
public function query ($query, $params = array()) {
$stmt = $this->dbh->prepare($query);
$stmt->execute($params);
2018-06-17 14:52:58 -06:00
$this->last_error_info = $stmt->errorInfo();
2017-12-24 12:00:45 -07:00
return $stmt;
}
2017-12-24 13:09:05 -07:00
public function lastInsertId () {
return $this->dbh->lastInsertId();
}
public function errorInfo () {
return $this->dbh->errorInfo();
}
2017-12-24 12:00:45 -07:00
}