Monday, 19 August 2013

MySQLi - SELECT * (ALL) Prepared Statement

MySQLi - SELECT * (ALL) Prepared Statement

I am trying to use a prepared statement for a SELECT * query. I am running
in the difficulty of binding the result. Because this is a SELECT * query
I am unaware of the column count. It would seem that binding the result to
an array would solve this, but I cannot find if this is possible or how to
do this. I looked into this answer, however, when I tried it I exhausted
the memory size (90MB).
if (!($stmt = $this->mysqli->prepare("SELECT * FROM Table WHERE id=?"))) {
$errors[] = "Database Error: Prepare failed: (" . $this->mysqli->errno .
") " . $mysqli->error; }
if (!$stmt->bind_param("s", $id)) { $errors[] = "Database Error: Binding
parameters failed: (" . $stmt->errno . ") " . $stmt->error; }
if (!$stmt->execute()) { $errors[] = "Database Error: Execute failed: (" .
$stmt->errno . ") " . $stmt->error; }
if (!$stmt->bind_result($array)) { $errors[] = "Database Error: Binding
result failed: (" . $stmt->errno . ") " . $stmt->error; }
$stmt->fetch();
$stmt->close();
return array( "array" => $array );

No comments:

Post a Comment