You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
//post properties
public $id;
public $category_id;
public $category_name;
public $title;
public $body;
public $author;
public $created_at;
//constructor
public function __construct($db)
{
$this->conn = $db;
}
//get posts
public function read(){
//creat query
$query = 'SELECT
C.name as category_name,
p.id,
p.category_id,
p.title,
p.body,
p.author,
p.created_at
FROM
' .$this->table. ' p
LEFT JOIN
categories c ON p.category_id = c.id
ORDER BY
p.created_at DESC';
//prepare statement
$stmt = $this->conn->prepare($query);
//execute
$stmt->execute();
return $stmt;
}
I'm having this trouble, any suggests?
Thank you for the codes
Post.php
`<?php
class Post{
//DB
private $conn;
private $table = 'posts';
}`
Database.php
`<?php
/**
*
*/
class Database
{
private $host = 'localhost';
private $db_name = 'testt';
private $username = 'root';
private $password = '';
private $conn;
}
?>`
read.php
`<?php
//Headers
header('Access-Control-Allow-Origin: *');
header('Content-Type:application/json');
include_once 'E:/Work/Aptech/XAmpp/htdocs/myproject/rest/Database.php';
include_once 'E:/Work/Aptech/XAmpp/htdocs/myproject/rest/models/Post.php';
//Install DB & connect
$database = new Database();
$db = $database->connect();
//Instantiate Post object
$post = new Post($db);
//Blog post query
$result = $post->read();
//Get row count
$num = $result->rowCount();
//check if any posts
if($num>0)
{
//post array
$posts_arr = array();
$posts_arr['data']=array();
}else{
//no post
echo json_encode(
array('message'=>'No Posts Found')
);
}
`
The text was updated successfully, but these errors were encountered: