Using Fetch Choices

Author Topic: Using Fetch Choices  (Read 791 times)

Offline chinmay.sahooTopic starter

  • Trade Count: (0)
  • Full Member
  • ***
  • Thank You 2
  • Posts: 159
  • Karma: 0
    • Hot Shaper
Using Fetch Choices
« on: 06-30-2016, 05:59:27 »
When you use prepare and execute, you have the choice of a number of formats in which data can be returned. The example we saw used the PDO::FETCH_ASSOC option with the fetch method, because it returns data in a format that will be very familiar for PHP4 users: an associative array.

If you’d rather use only object-oriented code in your application, you could instead employ the fetchObject method, which, as the name implies, returns the result set as an object. Here’s how the whileloop will look when the fetchObjectmethod is used:

Quote
while ($row =
$stmt->fetchObject()
)
{
print $row->Name . "\t";
print $row->CountryCode . "\t";
print $row->Population . "\n";
}


 

Related Topics

  Subject / Started by Replies Last post
1 Replies
1587 Views
Last post 03-25-2013, 02:22:46
by convergent
0 Replies
1509 Views
Last post 07-13-2015, 14:59:34
by download69
0 Replies
867 Views
Last post 07-28-2015, 06:48:20
by parththakkar
0 Replies
333 Views
Last post 10-08-2016, 03:04:16
by helenedwards