Join Jon Peck for an in-depth discussion in this video Creating a database class, part of Object-Oriented Programming with PHP.
- View Offline
- Exercise Files
Often it's optimal to only connect to the database once. …I could connect and disconnect every time I needed to query the database, but …that's hugely inefficient. …I could use a global variable assigned to the connection, but that's fragile at …best, as anything could manipulate it. …It's better to control access, and restrict the number of connections. …I am going to demonstrate how to create a simple, but still useful class that …will only allow one connection to the database at one time. …It'll provide access throughout the application, and minimize the possibility for corruption. …To do that, I'm going to use the object- oriented database connection from the …MySQLi improved extension (or MySQLi). …Create a new file in your Exercise folder, and call it class_Database.inc. …Start a new class definition for the database. And, add some documentation. Only …one connection is allowed. …The first property to create will contain the connection. …Make it private, as the class will be controlling access to it. …
- Historical overview of object-oriented PHP
- Defining classes
- Creating a method/object context with $this
- Accessing classes without instantiation
- Creating a database class
- Extending and abstracting classes
- Cloning and comparing objects
- Error handling with exceptions
- Implementing design patterns, such as the factory and strategy patterns
Skill Level Intermediate
PHP with MySQL Beyond the Basicswith Kevin Skoglund10h 26m Intermediate
1. Introduction to Object-Oriented Programming
2. Creating Your First Object
3. Overloading with Magic Methods
Overloading property access6m 37s
4. Accessing Classes without Instantiation
5. Class Relationships and Interactions
6. Built-In PHP Objects
Customizing PHP exceptions4m 23s
7. Design Patterns
- 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.Cancel
Take 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.