mirror of
https://github.com/Floriansylvain/projet_programmation_web.git
synced 2026-08-19 19:53:18 +02:00
✨ Introducing API feature (get these by author name).
This commit is contained in:
@@ -0,0 +1,13 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
require_once("class/dump.php");
|
||||||
|
|
||||||
|
$author_name = $_GET['author'];
|
||||||
|
|
||||||
|
$these_array = dump::getTheseByAuthor($author_name);
|
||||||
|
|
||||||
|
$json = json_encode($these_array, JSON_PRETTY_PRINT);
|
||||||
|
|
||||||
|
echo '<pre>';
|
||||||
|
var_dump($json);
|
||||||
|
echo '</pre>';
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
require_once("these.php");
|
||||||
|
|
||||||
class dump {
|
class dump {
|
||||||
private these $these;
|
private these $these;
|
||||||
|
|
||||||
@@ -14,6 +16,23 @@ class dump {
|
|||||||
return date("Y-m-d", strtotime($old_date));
|
return date("Y-m-d", strtotime($old_date));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function getTheseByAuthor($author) : array {
|
||||||
|
$theses_array = [];
|
||||||
|
|
||||||
|
$pdo = new PDO('mysql:host=localhost;dbname=projet_prog_web;charset=utf8', 'root', 'root');
|
||||||
|
$stmt = $pdo->query("SELECT * FROM theses WHERE author = '$author';");
|
||||||
|
while ($obj = $stmt->fetchObject()) {
|
||||||
|
$i = 0;
|
||||||
|
$theses_array[`$i`] = array();
|
||||||
|
foreach ($obj as $elem) {
|
||||||
|
array_push($theses_array[`$i`], empty($elem) ? "NULL" : $elem);
|
||||||
|
$i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $theses_array;
|
||||||
|
}
|
||||||
|
|
||||||
public function sendThese() {
|
public function sendThese() {
|
||||||
$data = [
|
$data = [
|
||||||
'author' => $this->these->getAuthor(),
|
'author' => $this->these->getAuthor(),
|
||||||
@@ -39,5 +58,4 @@ class dump {
|
|||||||
$stmt= $pdo->prepare($sql);
|
$stmt= $pdo->prepare($sql);
|
||||||
$stmt->execute($data);
|
$stmt->execute($data);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user