0
我正试图在数组中获取我的结果行。当我运行的代码,它告诉我下面的:
Call to a member function fetch() on boolean in file.php on line 69
我做了以下
$query = "INSERT INTO table(info) VALUES(:info)";
$params = array(':info' => $_POST['info']);
try {
$stmt = $db->prepare($query);
$result = $stmt->execute($params);
}
catch (PDOException $ex) {
$response["error"] = TRUE;
$response["error_msg"] = "Insertion Error. Please Try Again";
echo $response["error_msg"];
die(json_encode($response));
}
while($row = $result->fetch()) {
}
echo $row["info"];
我是新来的PHP,所以我不能完全肯定我在做什么错在这里。如有必要,我可以澄清任何事情。所有帮助表示赞赏!
你需要明白'INSERT'查询不返回任何形式的数据库,它只会根据成功执行返回'true或false'。 'SELECT'查询将从数据库中返回一堆行的'resultset object'。在那你可以申请'fetch()'。 –