Query via PDO


require_once __DIR__ . '/config.php';
class API {
    function Select(){
        $db = new Connect;
        $users = array();
        $data = $db->prepare('SELECT * FROM users 
        ORDER BY id');
        $data->execute();
        while($OutputData = $data->fetch
        (PDO::FETCH_ASSOC))
        {
            $users[$OutputData['id']] = array(
                'id'    => $OutputData['id'],
                'name'    => $OutputData['name'],
                'sign'    => $OutputData['sign']
            );
        }
        return json_encode($users);
    }
}

$API = new API;
   
echo $API->Select();

                            

Query via $this


function readAll(){
        
    //select all query
    $query = "SELECT c.name as category_name, p.id, 
    p.name, p.description, p.price, p.category_id, 
    p.created
    FROM 
    " . $this->table_name . " p
    LEFT JOIN 
    categories c 
    ON p.category_id = c.id
    ORDER BY 
    p.created DESC";
                                    
    //prepare query statement
    $stmt = $this->conn->prepare($query);
                                    
    //execute query
    $stmt->execute();
    return $stmt;
}