我有一個數據庫,其中我有user_id
& associated_id
。單個user_id
可以有多個associated_id
。現在我想將所有associated_id
s取到一個數組中。我已經嘗試過這種方法,但不知道如何讓它們在數組中。如何使用php中的準備語句從數據庫中獲取數據?
$stmt = $this->conn->prepare("SELECT * FROM my_contacts WHERE user_id = ?");
$stmt->bind_param("s", $user_id);
if ($stmt->execute())
{
while ($stmt->fetch())
{
//what to write here
}
//echo var_dump($user);
$stmt->close();
}
您是否嘗試過Google? http://php.net/manual/de/pdostatement.fetch.php – Jens