简体   繁体   English

(JSON 文件)在 Wamp 中是否有任何 function 可以使其正常工作?

[英](JSON file)Is there any function to action in Wamp to make it work properly?

Here is my php file to retrieve users informations using recycleview in android.这是我的php文件,用于使用recycleview中的 recycleview 检索用户信息。 but it does not work I don't know.但它不起作用我不知道。 I need some help Here, image is TEXT and String , the others are varchar String also in my database 'xxxxx' table---users我需要一些帮助在这里,图像是 TEXT 和String ,其他的是 varchar String也在我的数据库 '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();
?>

You have made a lot of mistakes in your code.您在代码中犯了很多错误。 You have skipped mysqli ( query,fetch_assoc,num_rows should be mysqli_query,mysqli_fetch_assoc,mysqli_num_rows ) everywhere.您到处都跳过了mysqli query,fetch_assoc,num_rows应该是mysqli_query,mysqli_fetch_assoc,mysqli_num_rows If you don't want to write mysqli multiple times, you should try PDO.如果你不想多次写 mysqli,你应该尝试 PDO。 Here is an example:这是一个例子:

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';
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM