1

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

5
  • What DB interface is that? MySQLi? Commented Jan 29, 2012 at 1:24
  • what is $result? tried echoing it? Commented Jan 29, 2012 at 1:25
  • not sure about the answer but try to use $stmt instead of $result... Commented Jan 29, 2012 at 1:26
  • @RobinVanPersi tried no success Commented Jan 29, 2012 at 1:37
  • @epic_syntax ok if $result is a boolean 1, why would $result->anythingatall work? Commented Jan 29, 2012 at 2:28

3 Answers 3

0
 $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.

Sign up to request clarification or add additional context in comments.

Comments

0

mysqli_stmt::execute does not return the result, only true or false. You fetch the result from the mysqli_stmt object itself. Please carefully read the examples at http://php.net/manual/en/mysqli-stmt.execute.php and http://php.net/manual/en/mysqli-stmt.fetch.php.

2 Comments

Please take a look at Robert Pitts answer stackoverflow.com/questions/5679600/…
Well, look at the manual. mysqli_stmt::execute does not return an object.
0

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))
    {

2 Comments

Please take a look on updated question: modified code by your suggestion. Nothing has changed
What if I want to get the nth result? MySQLi is f'ed up.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.