Creating an instance of a class from a result set


show more Creating an instance of a class from a result set provides you with in-depth training on Developer. Taught by David Powers as part of the Accessing Databases with Object-Oriented PHP show less
please wait ...

Creating an instance of a class from a result set

With MySQL Improved, you can create an instance of a custom class and initialize the object's properties with values from a database result. However, you need to be aware that MySQLi sets the objects properties before calling the class's constructor method. The following example shows how it works. This is car.ID, which you can find in the ch07 > 07_05 folder of the exercise files, along with the other files that will be used in this video.

Car.php contains the definition for a custom PHP class called car. The Constructor method takes a single argument, the car's ID, which is then used to set the car ID property. Four other properties are set to default values in the constructor. The class uses the magic set and get methods to set and get the values of properties that don't have their own setter and getter methods. And down at the bottom, the definition of the magic toString returns HTML that displays the objects properties and their values.

So let's use this to create an instan...

Creating an instance of a class from a result set
Video duration: 4m 35s 3h 47m Intermediate

Viewers:

Creating an instance of a class from a result set provides you with in-depth training on Developer. Taught by David Powers as part of the Accessing Databases with Object-Oriented PHP

Subject:
Developer
Software:
PHP
Author:
please wait ...