I am creating a PHP application that has many structural interaction with the same database. I want to use a singleton factory to exclude the connection to the database and reduce the number of duplicate connections. I want to wrap the database square with some functions.
It would be very convenient if I can do all this in the same class. I tried to use the singleton factory (that seemed like a good idea at the time), only to realize that it seems that other sections would have to be returned to be useful, whether the singleton factory and database wrapping Is there an easy way to add functionality together, or should I just give the functions to wrap the database in another category?
Fixed private $ instance = array (); Personal function __construct ($ name) {switch ($ name) {// select db connection} $ this- & gt; Db = $ this- & gt; GetDb (); Return; } Secure function __clone () {} public static function singleton ($ name) {if (!! (self: $ example [name $]); {$ c = __CLASS__; self :: $ example [$ name] = new $ C ($ name);} Return self: $ example [$ name];} Public function wrapper function () {// luggage}
Comments
Post a Comment