- PHP 7 Programming Blueprints
- Jose Palala Martin Helmich
- 231字
- 2021-07-08 11:14:09
Chapter 1. Create a User Profile System and use the Null Coalesce Operator
To begin this chapter, let's check out the new null coalesce in PHP 7. We'll also learn how to build a simple profiles page with listed users that you can click on, and create a simple CRUD-like system which will enable us to register new users to the system and delete users for banning purposes.
We'll learn to use the PHP 7 null coalesce operator so that we can show data if there is any, or just display a simple message if there isn't any.
Let's create a simple UserProfile
class. The ability to create classes has been available since PHP 5.
A class in PHP starts with the word class
, and the name of the class:
class UserProfile { private $table = 'user_profiles'; } }
We've made the table private and added a private
variable, where we define which table it will be related to.
Let's add two functions, also known as a method, inside the class to simply fetch the data from the database:
function fetch_one($id) { $link = mysqli_connect(''); $query = "SELECT * from ". $this->table . " WHERE `id` =' " . $id "'"; $results = mysqli_query($link, $query); } function fetch_all() { $link = mysqli_connect('127.0.0.1', 'root','apassword','my_dataabase' ); $query = "SELECT * from ". $this->table . "; $results = mysqli_query($link, $query); }
- UI設(shè)計(jì)基礎(chǔ)培訓(xùn)教程
- Node.js 10實(shí)戰(zhàn)
- 企業(yè)級(jí)Java EE架構(gòu)設(shè)計(jì)精深實(shí)踐
- Mastering Adobe Captivate 2017(Fourth Edition)
- Python測(cè)試開(kāi)發(fā)入門(mén)與實(shí)踐
- Building RESTful Python Web Services
- Swift 4從零到精通iOS開(kāi)發(fā)
- Web前端應(yīng)用開(kāi)發(fā)技術(shù)
- Emgu CV Essentials
- Vue.js 3應(yīng)用開(kāi)發(fā)與核心源碼解析
- C陷阱與缺陷
- Learning Splunk Web Framework
- Python Web自動(dòng)化測(cè)試設(shè)計(jì)與實(shí)現(xiàn)
- 數(shù)據(jù)結(jié)構(gòu):Python語(yǔ)言描述
- 亮劍ASP.NET項(xiàng)目開(kāi)發(fā)案例導(dǎo)航