MySQL fetch命令不返回数据

时间:2015-11-14 20:49:20

标签: php mysql database mysqli

希望PHP脚本从数据库中提取所有数据,并在屏幕上显示。但是找不到最有效的方法来显示记录而不使用$ query_params变量,因为它会生成带有参数的错误但是没有数组就无法运行?

//initial query
$query = "Select * FROM tbl_data";

//execute query
try {
$stmt   = $db->prepare($query);
$result = $stmt->execute($query_params);
}
catch (PDOException $ex) {
$response["success"] = 0;
$response["message"] = "Database Error!";
die(json_encode($response));
}

这是显示代码

$rows = $stmt->fetchAll();
if ($rows) {
$response["success"] = 1;
$response["message"] = "Post Available!";
$response["posts"]   = array();

foreach ($rows as $row) {
    $post             = array();
    $post["username"] = $row["username"];
    $post["title"]    = $row["title"];
    $post["message"]  = $row["message"];

如果你能提供帮助,我将非常感激,谢谢!

0 个答案:

没有答案
相关问题