我试图从mysql数据库获取值并从php创建json。但我总是得到“虚假”的答复。尝试编码json时出现错误php
我的查询运行正常。
<?php
header("Content-type: text/html; charset=utf-8");
$servername = "localhost";
$username = "root";
$password = "root";
$dbname = "test";
$charset="UTF8";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sth = mysqli_query("select
a.id,
a.fname,
a.mname,a.lname,a.country,a.city,a.dob,a.role,
a.email,
b.mobile,b.skypeid,b.address,b.languages,
c.height,
c.width,
c.skin,
c.bust,
c.waist,
c.hips,
c.shoesize,
c.hair,
c.eye,
c.comments,
d.movie,
d.advertisement,
d.brandpromotional,
d.danceshow,
d.runway,
d.catalog,
d.editorial,
d.fit,
d.casual,
d.corporate,
d.swimwear,
d.fitness,
d.magazine,
d.lingerie,
d.glamour,
d.alternative,
d.hair,
d.legs,
d.hands,
d.webmodel,
d.social,
d.experience
from
basicinfo a
join contactdetails b
on a.email=b.email
join measurements c
on a.email = c.email
join areainterest d
on a.email=d.email
where a.role='Model'");
$rows = array();
while($r = mysqli_fetch_assoc($sth)) {
$rows[] = $r;
}
print json_encode($rows);
?>
请帮我
你什么你json_encode之前获得,当你'的var_dump($行)'对不对? –
可能重复的[json \ _encode()返回false](http://stackoverflow.com/questions/19440529/json-encode-returns-false) –
我得到这一个数组(0){} – Bangalore