fetch()
// Returns an array for the next row in the result set. This array
// is indexed by both a string index for the column name and a numeric
// index for the column position. If no array is available, this
// method returns a FALSE value.
closeCursor()
// Closes the cursor and frees the connection to the server so
// other SQL statements may be issued.
$query = "SELECT productCode, productName, listPrice
FROM products
WHERE productID = :product_id";
$statement = $db->prepare($query);
$statement->bindValue(':product_id', $product_id);
$statement->execute();
$product = $statement->fetch();
$statement->closeCursor();
$product_code = $product['productCode'];
$product_name = $product['productName'];
$product_list_price = $product['listPrice'];
$product_code = $product[0];
$product_name = $product[1];
$product_list_price = $product[2];
fetch() method of a PDOStatement object to get an array for the first row (or next row) of a result set. Then, you can use column names or numeric indexes to access the data that’s stored in that row.fetch() method of a PDOStatement object to get an array for the first row (or next row) of a result set. Then, you can use column names or numeric indexes to access the data that’s stored in that row.