php get data from prepared select code example
Example 1: php prepared statement select
$sql = "SELECT * FROM users WHERE id=?";
$stmt = $conn->prepare($sql);
$stmt->bind_param("i", $id);
$stmt->execute();
$result = $stmt->get_result();
while ($row = $result->fetch_assoc()) {
echo $row['name'];
}
$sql = "SELECT user FROM users WHERE id=?";
$stmt = $conn->prepare($sql);
$stmt->bind_param("i", $id);
$stmt->execute();
$result = $stmt->get_result();
$user = $result->fetch_assoc();
$sql = "UPDATE users SET rank=?, status=? WHERE id=?";
$sql = "DELETE FROM users WHERE id=?";
$stmt = $conn->prepare($sql);
$stmt->bind_param('sss', $rank, $status, $id);
$stmt->execute();
Example 2: php get data from prepared select
public function get_data_from($id){
$request = "SELECT * FROM tableName WHERE id = ?";
$stmt = $this->dbh->prepare($request);
$stmt->execute( array($id) );
$result = $stmt->fetchAll();
return $result;
}