Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pdo fetchAll() returns empty array() [duplicate]

I have been trying for over a day now to get FetchAll() method to help me display array from database. But all my efforts have failed. Instead of the print_r() returning an array, it gives me this array(). Kindly, help me out. The code in class page :

class Article {
public function fetch_all(){
    global $conn;
    $ass = $conn->prepare("SELECT * FROM articles");
    $ass->execute();
     return $ass->fetchAll();


    }

} 

while the code in display page is:

$article = new Article;
$articles = $article->fetch_all();
 print_r($articles);
like image 482
user2947216 Avatar asked Jun 30 '26 18:06

user2947216


1 Answers

$query is not defined in your code, $ass->fetchAll(); is what you should have.

like image 191
Musa Avatar answered Jul 03 '26 08:07

Musa



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!