i had a headache over the last few days trying to understand this snippet of code. it's about retrieving data from a database table nothing hard (i'm using mysql) . but i'm trying to understand the code. here is the code:
<?php
include 'PDOconnect.php';
//Query
$result = $connection->query('SELECT * FROM video_games');
//Fetch
$data = $result->Fetch();
while ($data = $result->Fetch()) {
echo $data['name']."<br />";
}
?>
first let me explain, the second line is including the connection code to the database i'm using the PDO way of connecting. the connection is fine . my table is called video_games and it had a column called 'name'. and i'm trying with this code to retrieve all the data from the column 'name'.
1- so what i want to understand is what is the $result variable (line 6) , i've heard it's a Resource. what a resource in mysql means, and what's inside of the variable $result is it the whole table or what exactly ??
2- what the function fetch() does ?? it's confusing .
3- what i know from studying the basic syntax of php is that inside the while condition the value must be true in order to execute the code inside. but here there is ($data = $result->Fetch()) .
4- is the fetch() method automatically incremented ?? i mean why it is working successfully inside the while condition, so it must be incrementing over and over again ??
please help my mind is blowing right now.