i m trying to build a JSON array from mysql. it does not get the information from mysql
<?php
$host="localhost";
$pwd="";
$user="root";
$db="mydb";
$con=mysqli_connect($host,$user,$pwd,$db) or die('Unable to connect');
if(mysqli_connect_error($con))
{
echo"failded to connect";
}
$query = mysqli_query($con,"select * from product");
if ($query)
{
while($row = mysqli_fetch_array($query))
{
$flag[] = $row;
}
print(json_encode($flag));
}
mysqli_close($con);
?>
Notice: Array to string conversion in C:\wamp\www\new\count.php on line 19
What does this error mean and how do I fix it?
$flag = $row;instead of$flag[] = $row;as$rowis already an array I reckon.