…A really nice feature of PDO, is that you can loop…directly over a select query, without needing to store the result first.…I've got open pdo_loop.php, which you can find in…the Chapter 02 > 02_03 folder, of the exercise files.…The code on line three, includes the database…connection we created in the previous movie, and…the HTML contains a table, that'll be used to display the results of a select query.…
So, let's create that query, we'll create it…on the line after including the database connection.…We'll save it as SQL.…And, it will be select, name, meaning,…gender, from names, and then we'll have a little order…clause to it, so order by name.…And instead of submitting this query to the database and storing the result,…we can get direct access to each row, in a for each loop.…
So let's create that for each loop.…We need to go down into the HTML part of the…page, create a new line between the two rows on line 29.…Needs to be a php block.…And in there we'll have a for reach loop.…We use the data base connection.…
Author
Released
7/7/2014- Connecting to a database with PDO or MySQLi
- Fetching a result set
- Executing simple non-SELECT queries
- Sanitizing user input
- Binding input and output values
- Passing an array of values to the execute() method
- Working with advanced PDO fetch methods
- Executing a MySQLi transaction
- Freeing resources that are no longer needed
- Submitting multiple queries
- Creating an instance of a class from a result set
Skill Level Intermediate
Duration
Views
Related Courses
-
Advanced PHP: Debugging Techniques
with Jon Peck1h 29m Intermediate
-
Introduction
-
Welcome1m
-
Using the exercise files4m 56s
-
Setting SQLite permissions1m 11s
-
-
1. Why Use Object-Oriented PHP to Access a Database?
-
Using prepared statements4m 24s
-
Using transactions1m 43s
-
2. PHP Data Object (PDO) Basics
-
Fetching a result set8m 3s
-
Getting error messages7m 17s
-
3. PDO-Prepared Statements and Transactions
-
Using named parameters9m 51s
-
Binding results to variables7m 53s
-
Executing a transaction6m 54s
-
4. Advanced PDO Fetch Methods
-
Reusing a result set7m 53s
-
5. MySQL Improved Basics
-
Setting the character set1m 57s
-
Fetching the result7m 35s
-
Handling non-SELECT queries5m 27s
-
Getting error messages5m 47s
-
6. MySQLi Prepared Statements and Transactions
-
Binding output variables5m 6s
-
7. Diving Deeper into MySQLi
-
Using real_query()6m 1s
-
Submitting multiple queries6m 41s
-
Conclusion
-
PDO and MySQLi compared3m 31s
-
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.
CancelTake notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.
Share this video
Embed this video
Video: Looping directly over a SELECT query