Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/252.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/performance/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
正确的Php文件_Php_Performance - Fatal编程技术网

正确的Php文件

正确的Php文件,php,performance,Php,Performance,我编写了php代码,用于使用wamp服务器访问mysql数据库中的数据 这是我的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_conn

我编写了php代码,用于使用wamp服务器访问mysql数据库中的数据

这是我的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);
?>

尝试更改提取模式

if($row = mysqli_fetch_assoc($result))

尝试更改获取模式

if($row = mysqli_fetch_assoc($result))

mysqli_fetch_数组
还提供了带有自定义索引的结果

因此,您需要使用mysqli\u fetch\u assoc:

while($rows = mysqli_fetch_assoc($result)){
  //your code
}

mysqli_fetch_数组还提供了带有自定义索引的结果

因此,您需要使用mysqli\u fetch\u assoc:

while($rows = mysqli_fetch_assoc($result)){
  //your code
}

mysqli\u fetch\u数组
获取同时包含编号元素和关联元素的n数组。您想使用
mysqli\u fetch\u assoc

mysqli\u fetch\u数组
获取包含编号元素和关联元素的n个数组。你想在你的代码中使用“mysqli\u fetch\u assoc”这就是为什么你会得到上面的结果,使用“mysqli\u fetch\u assoc”而不是“mysqli\u fetch\u array”,你会得到只有列名的结果。

在你的代码中你使用了“mysqli\u fetch\u array”这就是为什么你会得到上面的结果,使用“mysqli_fetch_assoc”而不是“mysqli_fetch_array”,您将只获得列名的结果。

Imma直接在这里使用它,但您可能想开始使用PDO作为数据库抽象层?Imma直接在这里使用它,但您可能想开始使用PDO作为数据库抽象层?