Beginner's Question about accessing mysql using OOP

Posted by user345690 on Stack Overflow See other posts from Stack Overflow or by user345690
Published on 2010-05-20T03:27:31Z Indexed on 2010/05/20 3:30 UTC
Read the original article Hit count: 171

Filed under:
|
|

I am reading the PHP and mySQL web development book and so far been doing all the PHP and mysql using procedural. But then it talks about accessing mysql with objects.

This works for me:
//I define $db so can connect
$query="select * FROM testing";
$result=mysqli_query($db,$query);
while($row=mysqli_fetch_array($result)){
  //echo the data
}

But when I try to do it with classes, it doesn't
$query="select * FROM testing";
$result=$db->query($query);
$row=$result->fetch_assoc();

Do I have to write my own class so it defines what query and fetch_assoc does? Or what?

© Stack Overflow or respective owner

Related posts about beginner

Related posts about php