2

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?

zeckdude
  • 15,877
  • 43
  • 139
  • 187

1 Answers1

10

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
  • 40,769
  • 9
  • 59
  • 81
  • 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 Jun 07 '09 at 10:14
  • 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 Jun 07 '09 at 10:16
  • oh, i see. i'll give you one more then for your troubles – zeckdude Jun 07 '09 at 10:19
  • 1
    thanks, you didn't need to be bothered by this. after several time you get used to it. ;o) – Artem Barger Jun 07 '09 at 10:23
  • Link seems to be dead. It would be great if you added some other information to this answer (though it's been 11 years since you replied). – carloswm85 Jun 10 '21 at 20:56