Join David Powers for an in-depth discussion in this video Creating an instance of a specific class with a database result, part of PHP: Accessing Databases with PDO and MySQLi.
…We've seen how to set the properties of an…existing PHP object from the result of a select query.…PDO can also create a new object and set its properties, but you need to be…careful that default values in the object constructor…don't overwrite the values from the database result.…We'll use the same Car class as in the previous video.…And the script in fetch_class.php is also very similar.…The only difference is that we're not actually creating an object beforehand.…
We're going to use the results of the database query to create our new object.…Incidentally, you can find both of these files in…the chapter four, 04_03 folder of the exercise files.…So, we've got a prepared statement that is selecting…values from the cars database and it's using car_id.…That's got a question mark as the placeholder.…We then prepare the statement and then we execute the statement,…parsing at the value of car_id, which is bound to that placeholder.…So, we can now use the database result to…create an instance of the object that we want.…
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: Creating an instance of a specific class with a database result