Last active
December 12, 2015 02:58
-
-
Save ameliaikeda/4703298 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function get_user_array() { | |
if (isset($_SESSION["id"])) { | |
$sid = $_SESSION["id"]; | |
if ($query = $db->prepare("SELECT id, name, status from `users` where id=?")) { | |
$query->bind_param("i", $sid); | |
$query->execute(); | |
$query->bind_result($id, $name, $status); | |
if (!$query->fetch()) { | |
$query->close(); | |
$db->close(); | |
return false; // clunky, but that's what abstraction layers are for. | |
} | |
$query->close(); | |
$db->close(); | |
return array("name" => $name, "status" => $status, "id" => $id); | |
} else { | |
return false; | |
} | |
} else { | |
return false; | |
} | |
// counting users: | |
if ($query = $db->prepare("SELECT a, b, c FROM table WHERE x = ?")) { | |
$res = array(); | |
$query->bind_param("i", 3); | |
$query->bind_result($x, $y, $z); | |
$query->execute(); | |
$rows = $query->num_rows; | |
while ($query->fetch()) { | |
array_push($res, array($x, $y, $z)); | |
} | |
// closing/cleanup | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment