我编写了用于使用 wamp 服务器访问 mysql 数据库中的数据的 php 代码。
这是我的php代码…………
<?php
//connect to the db
$host="localhost"; // Host name
$user="root"; // Mysql username
$pswd=""; // Mysql password
$db="gpsvts_geotrack"; // Database name
// Table name
$conn = mysqli_connect($host,$user,$pswd,$db);
//mysql_select_db($db, $conn);
//run the query to search for the username and password the match
//$query = "SELECT * FROM "." ".$tbl_name. " "."WHERE uname = '$myusername' AND passwd= '$mypassword' ";
$query = "select user_master.uid,device_locator_tbl.imei,device_locator_tbl.speed,device_locator_tbl.datetime,device_locator_tbl.number,device_master.icon
from device_locator_tbl,device_master,device_registration,user_master where user_master.uid=device_registration.uid
AND device_registration.imei=device_master.imei AND device_registration.imei=device_locator_tbl.imei AND user_master.uid=126";
//$query = "SELECT uid FROM $tbl_name WHERE uname = '$un' AND passwd = '$pw'";
$result = mysqli_query($conn,$query) or die("Unable to verify user because : " );
//this is where the actual verification happens
if($row = mysqli_fetch_array($result))
//echo mysql_result($result,0); // for correct login response
{
$rows[] = $row;
}
// close the database connection
mysqli_close($conn);
// echo the application data in json format
echo json_encode($rows);
?>
当运行这个 php 文件时,我得到的结果如下....
[{"0":"126","uid":"126","1":"008873407616","imei":"008873407616","2":"36.4","speed":"36.4", "3":"2013-06-28 21:56:07","日期时间":"2013-06-28 21:56:07","4":"008873407616","数字":"008873407616", "5":"CAR","icon":"CAR"}]
我没有使用任何coloum名称来打印0,1,2,3,4,5...这里你可以看到0:126,它必须是uid:126。得到了。但我也得到了不必要的字段。如何克服这个问题。