From f6b8611d90fe1d814c9e7481742da01cdc9993f8 Mon Sep 17 00:00:00 2001 From: David Bailey Date: Mon, 23 Oct 2023 22:38:36 +0200 Subject: [PATCH] feat: work on testing out MySQLi adpater class --- www/router.php | 63 ++++---------------------------------------------- 1 file changed, 5 insertions(+), 58 deletions(-) diff --git a/www/router.php b/www/router.php index 091897e..38fb670 100644 --- a/www/router.php +++ b/www/router.php @@ -1,64 +1,11 @@ false - ]; - } - else { - $post_data["found"] = true; - $post_data["post_metadata"] = json_decode($post_data["post_metadata"]); - } - - return $post_data; -} - -function get_post_by_path($path) { - global $sql; - - $path = chop($path, '/'); - - $qry = "SELECT * FROM posts WHERE post_path = ?"; - - $stmt = $sql->prepare($qry); - $stmt->bind_param("s", $path); - $stmt->execute(); - - $post_data = $stmt->get_result()->fetch_assoc(); - - return process_post_data($post_data); -} - -function get_subposts($path) { - global $sql; - - $path = chop($path, '/'); - - $path_depth = substr_count($path, "/"); - - $qry = "SELECT post_path, post_metadata - FROM posts - WHERE (post_path LIKE CONCAT(?,'/%')) - AND post_path_depth = ? - ORDER BY post_create_time DESC - LIMIT 10"; - - $stmt = $sql->prepare($qry); - $stmt->bind_param("si", $path, $path_depth); - $stmt->execute(); - - $post_data = $stmt->get_result()->fetch_all(MYSQLI_ASSOC); - - $post_data = array_map('process_post_data', $post_data); - - return $post_data; -} +$adapter = new MySQLAdapter(); //if (!$sql) // { @@ -98,11 +45,11 @@ if($_SERVER['REQUEST_URI'] == '/') { echo json_encode(get_subposts($match[1])); } elseif(true) { - $post = get_post_by_path($_SERVER['REQUEST_URI']); + $post = $adapter->get_post_by_path($_SERVER['REQUEST_URI']); echo $twig->render('about.html', [ "post" => $post, - "subposts" => get_subposts($_SERVER['REQUEST_URI']) + "subposts" => $post['subposts'] ]); } elseif(preg_match('/^\/about(.html)?$/', $_SERVER['REQUEST_URI'])) {