0

On backend I have rest api and I call v1/task with ajax to get all user tasks

I have:

public function getAllUserTasks($user_id) {
        $stmt = $this->conn->prepare("SELECT t.* FROM tasks t, user_tasks ut WHERE t.id = ut.task_id AND ut.user_id = ?");
        $stmt->bind_param("i", $user_id);
        $stmt->execute();
        $tasks = $stmt->get_results();
        $stmt->close();
        return $tasks;
    }

but I got error:

<br />
<b>Fatal error</b>:  Call to undefined method mysqli_stmt::get_results() in <b>/home/agroagro/public_html/agroMobile/include/DbHandler.php</b> on line <b>281</b><br />

Here is my console screen: enter image description here

How I can solv ethis problem? Any replacment for this function?

LaraBeginer
  • 161
  • 1
  • 3
  • 14

1 Answers1

1

I think small mistake in your function

$tasks = $stmt->get_results();

it should be

$tasks = $stmt->get_result();

Or try by this way

$stmt->bind_result();
$tasks = $stmt->fetch();
jamseernj
  • 1,052
  • 11
  • 16
  • Call to undefined method mysqli_stmt::get_result() in /home/agroagro/public_html/agroMobile/include/DbHandler.php – LaraBeginer Dec 01 '14 at 11:53
  • How I can replace get_result with BIND and FETCH – LaraBeginer Dec 01 '14 at 11:55
  • but please write answer without get_result function ... I will try to restart apache – LaraBeginer Dec 01 '14 at 11:59
  • http://i.imgur.com/CdUKd9R.png – LaraBeginer Dec 01 '14 at 12:04
  • 1
    Check your php version also the $stmt->get_result() function works from PHP 5.3, also if you select the $stmt->bind_result(); method then you have to specify the column names as a parameter. http://stackoverflow.com/questions/8321096/call-to-undefined-method-mysqli-stmtget-result – jamseernj Dec 01 '14 at 12:14
  • PHP 5.4.0 ... please write answer for my code , how to specify column names... sory about trivial question I'm super beginer – LaraBeginer Dec 01 '14 at 12:16
  • when I change y code with your from answer I get: Call to a member function fetch_assoc() on a non-object in /home/agroagro/public_html/agroMobile/v1/index.php on line 155
    – LaraBeginer Dec 01 '14 at 12:17
  • and again dont work ... – LaraBeginer Dec 01 '14 at 12:18
  • Un comment this line "extension=php_mysqli_mysqlnd.dll in php.ini;" from your php.ini file and try with $stmt->get_result(); function. Ofcourse you get the Call to a member function issue while using $stmt->bind_result(); thats because there is empty parameters, you have to pass the column names as a parameters, if you want to fetch all the columns then you have to pass all the columns as a parameters. – jamseernj Dec 01 '14 at 12:27