🎨 Adding conf.php class to create PDO exclusively from this.

This commit is contained in:
Florian SYLVAIN
2021-09-24 11:51:27 +02:00
parent b0547ee0ee
commit f2f0ee96f0
4 changed files with 20 additions and 6 deletions
+15
View File
@@ -0,0 +1,15 @@
<?php
class conf
{
private pdo $pdo;
public function __construct()
{
$this->pdo = new PDO('mysql:host=localhost;dbname=projet_prog_web', 'root', 'root');
}
public function getPDO() : pdo {
return $this->pdo;
}
}
+5 -2
View File
@@ -1,6 +1,7 @@
<?php <?php
require_once("these.php"); require_once("these.php");
require_once("conf.php");
class dump { class dump {
private these $these; private these $these;
@@ -19,7 +20,8 @@ class dump {
public static function getTheseByAuthor($author) : array { public static function getTheseByAuthor($author) : array {
$theses_array = []; $theses_array = [];
$pdo = new PDO('mysql:host=localhost;dbname=projet_prog_web;charset=utf8', 'root', 'root'); $pdo_obj = new conf();
$pdo = $pdo_obj->getPDO();
$stmt = $pdo->query("SELECT * FROM theses WHERE author = '$author';"); $stmt = $pdo->query("SELECT * FROM theses WHERE author = '$author';");
$i = 0; $i = 0;
while ($obj = $stmt->fetchObject()) { while ($obj = $stmt->fetchObject()) {
@@ -54,7 +56,8 @@ class dump {
'date_update' => empty($this->these->getDateUpdate()) ? NULL : $this->these->getDateUpdate() 'date_update' => empty($this->these->getDateUpdate()) ? NULL : $this->these->getDateUpdate()
]; ];
$sql = "INSERT INTO theses (author, id_author, these_director, title, these_director_name_lastname, id_director, soutenance_establishment, id_establishment, discipline, status, date_first_registration, date_soutenance, language, id_these, online, date_publication, date_update) VALUES (:author, :id_author, :these_director, :title, :these_director_name_lastname, :id_director, :soutenance_establishment, :id_establishment, :discipline, :status, :date_first_registration, :date_soutenance, :language, :id_these, :online, :date_publication, :date_update)"; $sql = "INSERT INTO theses (author, id_author, these_director, title, these_director_name_lastname, id_director, soutenance_establishment, id_establishment, discipline, status, date_first_registration, date_soutenance, language, id_these, online, date_publication, date_update) VALUES (:author, :id_author, :these_director, :title, :these_director_name_lastname, :id_director, :soutenance_establishment, :id_establishment, :discipline, :status, :date_first_registration, :date_soutenance, :language, :id_these, :online, :date_publication, :date_update)";
$pdo = new PDO('mysql:host=localhost;dbname=projet_prog_web', 'root', 'root'); $pdo_obj = new conf();
$pdo = $pdo_obj->getPDO();
$stmt= $pdo->prepare($sql); $stmt= $pdo->prepare($sql);
$stmt->execute($data); $stmt->execute($data);
} }
-3
View File
@@ -1,3 +0,0 @@
<?php
$pdo = new PDO('mysql:host=localhost;dbname=projet_prog_web', 'root', 'root');
-1
View File
@@ -1,6 +1,5 @@
<?php <?php
require_once("../conf.php");
require_once("../class/these.php"); require_once("../class/these.php");
require_once("../class/dump.php"); require_once("../class/dump.php");