Beginner's Question about accessing mysql using OOP
- by user345690
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?