I have a table main_tag with structure as
1 id int(100)
2 name varchar(100)
3 description varchar(1000)
4 added_on timestamp
and have function of php that is as follows
function all_data_of_main_tag_table(){
include_once 'db.php';
$conn = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
$json = array();
$nameQuery ='SELECT * FROM `main_tag` WHERE 1';
echo '<br>'.$nameQuery.'<br>';
$rsnameQuery = $conn->query($nameQuery);
if($rsnameQuery === false){
echo 'hi'.'<br>';
trigger_error('Wrong SQL: '.$nameQuery.' Error: '.$conn->error, E_USER_ERROR);
}
else{
$rows_returned = $rsnameQuery->num_rows;
}
while($row = $rsnameQuery->fetch_assoc()){
$json =$row;
}
$conn->close();
return $json;
}
On running this function it is giving error:
{
"description": null,
"name": null,
"id": null
}
MySQL error: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 1
Wrong SQL:, but your message saysMySQL error:. It also doesn't print$nameQuerylike yourtrigger_error()call does.$json[] = $row;. You're overwriting the variable each time, so you only get the last row.