diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -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 diff --git a/.idea/GIT_ADITTA.iml b/.idea/GIT_ADITTA.iml new file mode 100644 index 0000000..c956989 --- /dev/null +++ b/.idea/GIT_ADITTA.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..d354a91 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/php.xml b/.idea/php.xml new file mode 100644 index 0000000..f324872 --- /dev/null +++ b/.idea/php.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..8306744 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/pdo.php b/pdo.php new file mode 100644 index 0000000..baa2e6a --- /dev/null +++ b/pdo.php @@ -0,0 +1,16 @@ +console.log('Error PDO : " . $e->getMessage() . "' );"; +} diff --git a/sql_utilis.php b/sql_utilis.php new file mode 100644 index 0000000..431afcf --- /dev/null +++ b/sql_utilis.php @@ -0,0 +1,57 @@ +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); + } + +} \ No newline at end of file