本文主要和大家分享php连接数据库之查询数据,主要以代码的方法,希望能帮助到大家。header("Access-Control-Allow-Origin: *");
header("Control-type:application/json;charset='utf-8'");
$con = mysql_connect('url','username','pwd');
$mysql_db = mysql_select_db('npi',$con) or die ('连接失败'.mysql_errno);
mysql_query("set names 'uft8'");
$sql = "select lineno from lineno6s";
$query = mysql_query($sql);
if($query&&mysql_num_rows($query)){
while ($row = mysql_fetch_assoc($query)) {
$data [] = $row;
}
}
else if(mysql_num_rows($query)==null){
$data = '{content:"blank"}';
echo $data;
return;
}
$jsondata = json_encode($data,JSON_UNESCAPED_UNICODE);
echo $jsondata;
mysql_close();
exit();
相关推荐: