[英]How can i use array_push by a php extension pdo?
我想知道如何使用 pdo 推送獲取的數組。我們該怎么做?我知道這可能是可能的,所以我需要幫助。
$done = false;
$name = $_SESSION['people'] ['name'];
$result = array();
$query = 'SELECT * FROM people WHERE name = :me';
$query_paramt = array(
':me' => $name
);
try
{
// Execute the query to create the user
$stmts = $db->prepare($query);
$results = $stmts->execute($query_paramt);
if($results == true)
{
$done = true;
}
}
catch(PDOException $ex)
{
// Note: On a production website, you should not output $ex->getMessage().
// It may provide an attacker with helpful information about your code.
die("Failed to run query: " . $ex->getMessage());
}
$row = $stmts ->fetchAll();
實際上,我想對獲取的數據使用 array_push 並將所有數據保存在$result
數組中,之后我打算將其編碼為 json 格式,例如:-
echo json_encode(array("result" => $result));
做這樣的事情會將 foo 添加到從 PDO 返回的數組中。
$arr = $pdo->fetchAll();
array_push($arr,"foo");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.