feat: work on testing out MySQLi adpater class
Some checks reported warnings
/ phplint (push) Has been cancelled
Some checks reported warnings
/ phplint (push) Has been cancelled
This commit is contained in:
parent
8f9d94faab
commit
f6b8611d90
1 changed files with 5 additions and 58 deletions
|
@ -1,64 +1,11 @@
|
|||
<?php
|
||||
|
||||
require_once 'vendor/autoload.php';
|
||||
require_once 'mysql_adapter.php';
|
||||
|
||||
// $sql = mysqli_connect('mysql', 'root', 'example', 'dragon_fire');
|
||||
|
||||
$sql = mysqli_connect('mysql', 'root', 'example', 'dragon_fire');
|
||||
|
||||
function process_post_data($post_data) {
|
||||
if($post_data == null) {
|
||||
$post_data = [
|
||||
"found" => 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'])) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue