parent
5783e51cb5
commit
7f6b0f4bcb
@ -1,33 +1,32 @@
|
||||
<?php
|
||||
class Connection extends PDO {
|
||||
class Connection extends PDO {
|
||||
|
||||
private $stmt;
|
||||
private $stmt;
|
||||
|
||||
public function __construct(string $dsn, string $username, string $password) {
|
||||
public function __construct(string $dsn, string $username, string $password) {
|
||||
|
||||
parent::__construct($dsn,$username,$password);
|
||||
$this->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||
}
|
||||
parent::__construct($dsn,$username,$password);
|
||||
$this->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||
}
|
||||
|
||||
|
||||
/** * @param string $query
|
||||
* @param array $parameters *
|
||||
* @return bool Returns `true` on success, `false` otherwise
|
||||
*/
|
||||
/**
|
||||
* @param string $query
|
||||
* @param array $parameters *
|
||||
* @return bool Returns `true` on success, `false` otherwise
|
||||
*/
|
||||
public function executeQuery(string $query, array $parameters = []) : bool{
|
||||
$this->stmt = parent::prepare($query);
|
||||
foreach ($parameters as $name => $value) {
|
||||
$this->stmt->bindValue($name, $value[0], $value[1]);
|
||||
}
|
||||
|
||||
public function executeQuery(string $query, array $parameters = []) : bool{
|
||||
$this->stmt = parent::prepare($query);
|
||||
foreach ($parameters as $name => $value) {
|
||||
$this->stmt->bindValue($name, $value[0], $value[1]);
|
||||
}
|
||||
|
||||
return $this->stmt->execute();
|
||||
}
|
||||
return $this->stmt->execute();
|
||||
}
|
||||
|
||||
public function getResults() : array {
|
||||
return $this->stmt->fetchall();
|
||||
|
||||
}
|
||||
}
|
||||
public function getResults() : array {
|
||||
return $this->stmt->fetchall();
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
include_once("../business/Task.php");
|
||||
include_once("..Connection.php");
|
||||
|
||||
class TaskGateway
|
||||
{
|
||||
// connection attribute
|
||||
private Connection $con;
|
||||
|
||||
// constructor
|
||||
public function __construct(Connection $con){
|
||||
$this->con=$con;
|
||||
}
|
||||
|
||||
// functions
|
||||
// code de retour pour les fonctions i,u,d?
|
||||
public function insert(Task $t){
|
||||
// insert a new task
|
||||
}
|
||||
|
||||
public function update(Task $t){
|
||||
// update a task
|
||||
}
|
||||
|
||||
public function delete(Task $t){
|
||||
// delete a task
|
||||
}
|
||||
|
||||
# comment ça marche ?
|
||||
public function Find(array $elements):array{
|
||||
// Find a task by multiple elements
|
||||
// returns the array of found tasks
|
||||
}
|
||||
}
|
||||
?>
|
@ -0,0 +1,4 @@
|
||||
<?php
|
||||
static $user = 'nifranco';
|
||||
static $pass = 'f3wn5ady';
|
||||
?>
|
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
require("../dal/Connection.php");
|
||||
require("credentials.php");
|
||||
|
||||
$prio='urgent';
|
||||
$con = new Connection('mysql:host=localhost;dbname=phpproject',$user,$pass);
|
||||
$query = 'SELECT id FROM Tache WHERE priorite=:prio';
|
||||
|
||||
$con->executeQuery($query,array(
|
||||
':prio'=>array($prio,PDO::PARAM_STR)));
|
||||
|
||||
$results=$con->getResults();
|
||||
foreach($results as $row)
|
||||
echo $row['id'];
|
||||
|
||||
echo "</br> its all good!";
|
||||
?>
|
Loading…
Reference in new issue