Loading...
「ツール」は右上に移動しました。
利用したサーバー: wtserver1
0いいね 211 views回再生

How to Load MySQL/MariaDB Rows Directly into PHP Class Objects

In this beginner tutorial, we'll fetch database (MySQL/MariaDB) data into an array of PHP Class objects using PDO's FETCH_CLASS and FETCH_UNIQUE attributes. We'll also use PHP 8.1's new "readonly" modifier feature that eliminates the need to write "getter" functions in our class.

If you need help setting up a local server, check out my "how to" on setting up Apache, PHP, and MariaDB:
[short]    • Install/Update Laragon with PHP 8.x, Maria...  
[detailed]    • Install PHP, MariaDB, Apache, VSCode, Lara...  

0:00 Overview
0:43 Create PHP Class Model
1:08 Use PHP 8.1 "readonly" modifier
2:17 FETCH_CLASS from database to PHP class
5:21 Deal with Nullable data type
6:26 FETCH_UNIQUE to use Primary Key as array index
8:03 Wrap up

コメント