I want to run a SELECT query and fetch data as associative array and echo the fetched data.
In procedural style I would use mysqli_fetch_array(). But I am now trying OOP style.
I have tried this code:
$con= new mysqli('localhost','root','','afiliate');
$query="SELECT * FROM product WHERE ID=? ";
$stmt->bind_param("i",$ID); /* $ID has a value, it's ok */
$stmt->execute();
$result=$con->query($query);
while($row=$result->fetch_row()){
echo $row['name'];
}
And the error I get is:
Fatal error: Call to a member function fetch_row() on boolean in /opt/lampp/htdocs/afiliate/product_details_individual.php on line 18
How can I fetch data and echo them?
$result->fetch_array();if (!$result=$con->query($query)) { // in case of unsuccess it returns false;$result->fetch_object('product');but you will need to define a classproductand have your db returning data matching the class definition.preparemethod beforebind_param. You don't do it. Your query not correct.$resultget false. You use metod with false but object