DEV Community

Elijah Emmanuel
Elijah Emmanuel

Posted on

Please How can I convert the following object oriented PDO fetch_assoc to MYsqli Format below.

Hi Great Developers, I am having a difficult time fetching data from my database using object PHP as below.

So I have two pages,

  • One for fetching data from my DB and returning it

  • And another for displaying the data from my database fetched from the first page.

As Below
The code below is a function written with PDO

First page.

function get_messages() 
{
//fetch data from db

$sql="SELECT user_name, msg, timestamp FROM message_chat";

//prepare and execute. 
$stmt=$conn->prepare($sql);

$stmt->execute() ;

//Now this is the line thats making things complicated. 

return $stmt->fetchAll(PDO::FETCH_ASSOC) ;
} 
Enter fullscreen mode Exit fullscreen mode

Now, the second page is meant to return the generated data's from the above code, but its not happening.
Please how can I convert the above PDO fetch_assoc statement to mysqli so I can use it in my project.

Top comments (0)