Skip to main content

Fetch_array alternative for PHP prepared statements



UPDATE







$stmt = $this->db->prepare("

SELECT u.id, u.fname, u.lname, u.mname, u.type, u.email, u.salt,

u.pass, u.salt, u.approved, u.ban, u2.status

FROM `users` AS u

LEFT OUTER JOIN `log` AS u2

ON u2.user_id = u.id

WHERE u.email = ? LIMIT 1") or die($this->db->error);



$stmt->bind_param("s", $_POST['email']) or die($stmt->error);

$stmt->execute();

$stmt->store_result();

if ($stmt->num_rows == 0) {

die($this->ajax->respond(7));

}

$result = $stmt->get_result();

$data = $result->fetch_array(MYSQLI_BOTH);







Trying to fetch array but getting following error for last line







Fatal error: Call to a member function fetch_array() on a non-object







Can't get it work. Please help


Comments

  1. With get_result() you can get a resultset from the executed statement:

    $stmt->execute();
    $result = $stmt->get_result();
    while ($row = $result->fetch_array(MYSQLI_BOTH))
    {

    ReplyDelete
  2. $data = $stmt->fetchAll();


    PDO gives this beautiful function for that purpose.

    Edit: i thought it was PDO interface. Why you aren't using pdo? I find it way comfortable than mysqli.

    ReplyDelete

Post a Comment

Popular posts from this blog

Slow Android emulator

I have a 2.67 GHz Celeron processor, 1.21 GB of RAM on a x86 Windows XP Professional machine. My understanding is that the Android emulator should start fairly quickly on such a machine, but for me it does not. I have followed all instructions in setting up the IDE, SDKs, JDKs and such and have had some success in staring the emulator quickly but is very particulary. How can I, if possible, fix this problem?