diff options
author | Camil Staps | 2017-02-07 13:45:37 +0100 |
---|---|---|
committer | Camil Staps | 2017-02-07 13:45:37 +0100 |
commit | e88de614588f0316aa15d09d3cc72ce251fc63e8 (patch) | |
tree | b0db264078666826a4f57d6a3d3e171626d766e7 |
Initial commit
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | conf.php | 9 | ||||
-rw-r--r-- | list.php | 41 |
3 files changed, 51 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f606d5e --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +repo diff --git a/conf.php b/conf.php new file mode 100644 index 0000000..5765a11 --- /dev/null +++ b/conf.php @@ -0,0 +1,9 @@ +<?php +define('DB_HOST', 'localhost'); +define('DB_NAME', 'clpm'); +define('DB_USER', 'clpm'); +define('DB_PASS', 'password'); + +$db = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME); +if (mysqli_connect_errno()) + die('Connection to the database failed.'); diff --git a/list.php b/list.php new file mode 100644 index 0000000..24340a8 --- /dev/null +++ b/list.php @@ -0,0 +1,41 @@ +<?php +require_once('conf.php'); + +$repo = []; + +$stmt = $db->prepare( + 'SELECT `package`.`id`,`package`.`name`,`url`,`desc`,`author`.`name` ' . + 'FROM `package`,`author` ' . + 'WHERE `package`.`author_id` = `author`.`id`'); +$stmt->execute(); +$stmt->bind_result($id, $name, $url, $desc, $author); +while ($stmt->fetch() === true) { + $repo[] = [ + 'id' => $id, + 'name' => $name, + 'author' => $author, + 'desc' => $desc, + 'url' => $url, + 'versions' => [] + ]; +} +$stmt->close(); + +$stmt = $db->prepare( + 'SELECT `major`,`minor`,`revision`,`depends` ' . + 'FROM `version` WHERE `package_id`=?'); +$stmt->bind_param('i', $pkg); +$stmt->bind_result($maj, $min, $rev, $deps); +for ($i = 0; $i < count($repo); $i++) { + $pkg = $repo[$i]['id']; + $stmt->execute(); + while ($stmt->fetch() === true) { + $repo[$i]['versions'][] = [ + 'version' => [$maj, $min, $rev], + 'depends' => json_decode($deps) + ]; + } + unset($repo[$i]['id']); +} + +print(json_encode($repo)); |