MySQL to JSON in PHP -
MySQL to JSON in PHP -
i have basic mysql database table people
3 columns (id, name, distance
)
i trying output php json web app can pick up. tried using solution answer:
$sth = mysql_query($con,"select * people"); $rows = array(); while($r = mysql_fetch_assoc($sth)) { $rows[] = $r; } print json_encode($rows);
however returning blank array of []
.
update: changed mysqli , added dumps:
$sth = mysqli_query("select * events",$con); $rows = array(); var_dump($sth); while($r = mysqli_fetch_assoc($sth)) { var_dump($rows); $rows[] = $r; } print json_encode($rows);
returns:
null []
swap query , connection in mysql_query-statement:
$sth = mysql_query("select * people", $con);
besides that, mysql-library deprecated. if you're writing new code consider using mysqli_ or pdo.
php mysql json
Comments
Post a Comment