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

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -