PHP design pattern: singleton pattern
Application scenarios:
In a single http request, a database connection is used in multiple places, and with a singleton, you only need to create one connection.
A huge amount of memory space is wasted when a large class is instantiated multiple times. Using singleton mode allows multiple objects to share the static space of a class in memory.
Code example:
Verify:
$conn1=DBHelper::getInstance (); $conn2=DBHelper::getInstance (); echo $conn1= $conn2