Using Fetch Choices

Author Topic: Using Fetch Choices  (Read 667 times)

Offline chinmay.sahooTopic starter

  • Trade Count: (0)
  • Full Member
  • ***
  • Thank You 2
  • Posts: 153
  • Karma: 0
    • No Addiction
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
1530 Views
Last post 03-25-2013, 02:22:46
by convergent
1 Replies
1455 Views
Last post 02-17-2016, 01:39:45
by ShreyaKoushik
0 Replies
824 Views
Last post 07-28-2015, 06:48:20
by parththakkar
0 Replies
233 Views
Last post 10-08-2016, 03:04:16
by helenedwards