Question

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?

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top