|
|
@ -2,7 +2,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
namespace DAL;
|
|
|
|
namespace DAL;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
use Exception;
|
|
|
|
use PDO;
|
|
|
|
use PDO;
|
|
|
|
|
|
|
|
use Twig\Error\Error;
|
|
|
|
|
|
|
|
|
|
|
|
class Connection extends PDO
|
|
|
|
class Connection extends PDO
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -12,26 +14,39 @@ class Connection extends PDO
|
|
|
|
* @param string $dsn
|
|
|
|
* @param string $dsn
|
|
|
|
* @param string $username
|
|
|
|
* @param string $username
|
|
|
|
* @param string $password
|
|
|
|
* @param string $password
|
|
|
|
|
|
|
|
* @throws Exception
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public function __construct(string $dsn, string $username, string $password)
|
|
|
|
public function __construct(string $dsn, string $username, string $password)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
parent::__construct($dsn, $username, $password);
|
|
|
|
try{
|
|
|
|
$this->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
|
|
|
parent::__construct($dsn, $username, $password);
|
|
|
|
|
|
|
|
$this->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
|
|
|
|
|
|
|
}catch (\PDOException $e){
|
|
|
|
|
|
|
|
throw new Exception("PDO error con");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
catch (Error $e){
|
|
|
|
|
|
|
|
throw new Error("Error PDO");
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @param string $query to execute
|
|
|
|
* @param string $query to execute
|
|
|
|
* @param array $parameters to bind
|
|
|
|
* @param array $parameters to bind
|
|
|
|
* @return bool Returns `true` on success, `false` otherwise
|
|
|
|
* @return bool Returns `true` on success, `false` otherwise
|
|
|
|
|
|
|
|
* @throws Exception
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public function executeQuery(string $query, array $parameters = []): bool
|
|
|
|
public function executeQuery(string $query, array $parameters = []): bool
|
|
|
|
{
|
|
|
|
{
|
|
|
|
$this->stmt = parent::prepare($query);
|
|
|
|
try{
|
|
|
|
foreach ($parameters as $name => $value) {
|
|
|
|
$this->stmt = parent::prepare($query);
|
|
|
|
$this->stmt->bindValue($name, $value[0], $value[1]);
|
|
|
|
foreach ($parameters as $name => $value) {
|
|
|
|
}
|
|
|
|
$this->stmt->bindValue($name, $value[0], $value[1]);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return $this->stmt->execute();
|
|
|
|
return $this->stmt->execute();
|
|
|
|
|
|
|
|
}catch (\PDOException $e){
|
|
|
|
|
|
|
|
throw new Exception("PDO error");
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|