This commit is contained in:
Aditta Barua
2025-11-18 08:33:34 +01:00
parent 87a44a2002
commit 2d46362300
8 changed files with 123 additions and 0 deletions

8
.idea/.gitignore generated vendored Normal file
View File

@@ -0,0 +1,8 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

8
.idea/GIT_ADITTA.iml generated Normal file
View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

8
.idea/modules.xml generated Normal file
View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/GIT_ADITTA.iml" filepath="$PROJECT_DIR$/.idea/GIT_ADITTA.iml" />
</modules>
</component>
</project>

19
.idea/php.xml generated Normal file
View File

@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="MessDetectorOptionsConfiguration">
<option name="transferred" value="true" />
</component>
<component name="PHPCSFixerOptionsConfiguration">
<option name="transferred" value="true" />
</component>
<component name="PHPCodeSnifferOptionsConfiguration">
<option name="highlightLevel" value="WARNING" />
<option name="transferred" value="true" />
</component>
<component name="PhpStanOptionsConfiguration">
<option name="transferred" value="true" />
</component>
<component name="PsalmOptionsConfiguration">
<option name="transferred" value="true" />
</component>
</project>

7
.idea/vcs.xml generated Normal file
View File

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

0
README.md Normal file
View File

16
pdo.php Normal file
View File

@@ -0,0 +1,16 @@
<?php
$host = 'ma_bdd'; // nom du docker --name ma-base-sql
$db = 'Bibli';
$user = 'root';
$pass = '234516'; // TODO : password à variabiliser
$charset = 'utf8mb4';
$dsn = "mysql:host=$host;dbname=$db;charset=$charset";
try {
$pdo = new PDO($dsn, $user, $pass);
$GLOBALS['BddIsConnected'] = true;
} catch (\PDOException $e) {
$GLOBALS['BddIsConnected'] = false;
echo "<script>console.log('Error PDO : " . $e->getMessage() . "' );</script>";
}

57
sql_utilis.php Normal file
View File

@@ -0,0 +1,57 @@
<?php
include("pdo.php");
function get_books($page = 1, $resultsPerPage = 10){
global $pdo;
$page = max(1, (int)$page);
$offset = ($page - 1) * $resultsPerPage;
$count_query = 'SELECT COUNT(*) FROM Livres AS L INNER JOIN Auteurs AS A ON L.auteur_id = A.auteur_id';
$count = $pdo->query($count_query)->fetchColumn();
$total_pages = ceil($count / $resultsPerPage);
$statement = $pdo->prepare('SELECT L.livre_id, L.titre, L.annee_publication, A.nom, A.prenom
FROM Livres AS L
INNER JOIN Auteurs AS A ON L.auteur_id = A.auteur_id
LIMIT :limit OFFSET :offset');
$statement->bindValue(':limit', $resultsPerPage, PDO::PARAM_INT);
$statement->bindValue(':offset', $offset, PDO::PARAM_INT);
$statement->execute();
return [
'books' => $statement->fetchAll(PDO::FETCH_ASSOC),
'current_page' => $page,
'total_pages' => $total_pages,
'total_results' => $count
];
}
function get_book($idBook = null) {
global $pdo;
if (is_numeric($idBook)) {
$statement = $pdo->prepare('SELECT L.titre, L.annee_publication, L.resume, A.nom, A.prenom, A.auteur_id
FROM Livres AS L
INNER JOIN Auteurs AS A ON L.auteur_id = A.auteur_id
WHERE L.livre_id = :id');
$statement->bindValue(':id', $idBook, PDO::PARAM_INT);
$statement->execute();
return $statement->fetch(PDO::FETCH_ASSOC);
}
}
function get_author($idAuthor = null) {
global $pdo;
if (is_numeric($idAuthor)) {
$statement = $pdo->prepare('SELECT A.nom, A.prenom, L.titre, L.livre_id
FROM Auteurs AS A
INNER JOIN Livres AS L ON L.auteur_id = A.auteur_id
WHERE A.auteur_id = :id');
$statement->bindValue(':id', $idAuthor, PDO::PARAM_INT);
$statement->execute();
return $statement->fetchAll(PDO::FETCH_ASSOC);
}
}