Retrieving objects from the database


show more Retrieving objects from the database provides you with in-depth training on Developer. Taught by Jon Peck as part of the Object-Oriented Programming with PHP show less
please wait ...

Retrieving objects from the database

I can also create a standard object straight from the database. One of the methods in MySQLi, fetch_ object, returns the current row of a result set as a standard class object. Let's add this to the address model. Let's go to the load function, which is currently a stub. I am going to add a connection to the database. Connect to the database, then write the query to retrieve a row from the address table by the primary key, address_id.

For safety, I'm using quotations around the identifier, and casting the identifier as an integer. sql_query equals SELECT everything from address, from address where address_id equals (int) $address_id.

The $result = mysqli ->query($sql_query). Use the mysqli result object to fetch an object from the database. If ($row = $result -> fetch_object. Display the row, then exit var_dump ($row) exit. Save, then open the demo script.

Remove the test object code, then add a title section for testing loading, followed by a call to the static method lo...

Retrieving objects from the database
Video duration: 5m 41s 1h 57m Intermediate Updated Apr 10, 2013

Viewers:

Retrieving objects from the database provides you with in-depth training on Developer. Taught by Jon Peck as part of the Object-Oriented Programming with PHP

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