tags:

views:

1145

answers:

1

I don't understand the concept of the fetch function.

I am doing a tutorial from 'PHP Solutions' book and i am using MySQL Improved to update something in the database.

Here is the code:

if (isset($_GET['article']) && !$_POST) {    

$sql = 'SELECT article_id, title, article
    FROM journal WHERE article_id = ?';

$stmt = $conn->stmt_init();

 if ($stmt->prepare($sql)) {      
    $stmt->bind_param('i', $_GET['article_id']);        
    $stmt->bind_result($article_id, $title, $article); 

   //execute the query, and fetch the result
   $OK = $stmt->execute(); 
   $stmt->fetch();
 }
}

So what is the fetch actually doing? I thought the execute() function is sending the information to the database and then it returns a true/false value to the $OK variable.

Is fetch() storing something in $stmt? Anybody have any idea what it is doing?

+6  A: 

Hard to anticipate what was before this line in your example, but in general fetch function is for getting current row from result set you receive from database. You can read here

Artem Barger
What was wrong with my explanation, so it was down-voted?
Artem Barger
it wasn't downvoted. I picked it as the accepted answer. Let me know if i did something wrong. Im new to Stackoverflow. Thanks for your help!
zeckdude
It wasn't you, but someone else, there a lot of people here which tends to down-vote without any explanation, just because they don't like the answer or it seems to them not correct.
Artem Barger
oh, i see. i'll give you one more then for your troubles
zeckdude
thanks, you didn't need to be bothered by this. after several time you get used to it. ;o)
Artem Barger