-1

这是我的phprecycleview文件,用于在 android中检索用户信息。但它不起作用我不知道。我需要一些帮助 这里,图像是 TEXT 和String,其他的也是 varcharString也在我的数据库 'xxxxx' 表中---用户


    <?php
include("connect.php");

if ($conn->connect_error) {

 die("Connection failed: " . $conn->connect_error);
} 

$sql = "SELECT nom, prenom, telephone, email,ncni, datenaissance, image FROM users ORDER BY id DESC ";

$result = $conn->query($sql);

if ($result->num_rows >0) {


 while($row[] = $result->fetch_assoc()) {

 $tem = $row;

 $json = json_encode($tem);


 }

} else {
 echo "No Results Found.";
}
 echo $json;
$conn->close();
?>

4

1 回答 1

0

您在代码中犯了很多错误。您到处都跳过了mysqli ( query,fetch_assoc,num_rows应该是mysqli_query,mysqli_fetch_assoc,mysqli_num_rows )。如果你不想多次写mysqli,你应该尝试PDO。这是一个例子:

try {
    $db = new PDO('mysql:host=localhost;dbname=DBNAME;charset=utf8',DBUSER, DBPASS);
    //echo "Connected";
}
catch (PDOException $e) {
    //print "Error!: " . $e->getMessage() . "<br/>";
    echo "Not Connected";
    die();
}


$query = $db->prepare("SELECT `nom`, `prenom`, `telephone`, `email`,`ncni`, `datenaissance`, `image` FROM `users` ORDER BY `id` DESC");
$query->execute();


if ($query->rowCount() > 0) {
    $data = $query->fetchAll(PDO::FETCH_ASSOC);

    echo json_encode($data);

}

else
{
   echo 'No Result Found';
}
于 2019-11-17T17:47:52.100 回答