18. عملی مثالSingletoneکل س
دیتابیس
class Db{
$_ =private static instance NULL;
$ =private connected FALSE;
$ =private mysql NULL;
$ =private result NULL;
__private function construct();
__public function destruct();
__private function clone();
public static function getInstance();
($ ,public function connect hostname
$ , $ , $ )username password database;
public function disconnect();
19. دیتابیس از استفاده اول مثال
' . .include db class php';
//create instane of Db class
$= ::db Db getInstance();
try{
$-> ($ [' '][' '],db connect cnfg db hostname
$ [' '][' ']cnfg db username,
$[' '][' '], $ [' ']cnfg db password cnfg db
[' ']database);
$= ' *query SELECT FROM user';
$-> ($ )db command query;
($ = $ -> ())while row db fetchAssoc{
$ [' ']echo row username.' : '
20. دیتابیس از استفاده دوم مثال
$= ::db Db getInstance();
try{
$-> ($ [' '][' '],db connect cnfg db hostname
$ [' '][' ']cnfg db username,
$[' '][' '], $ [' ']cnfg db password cnfg db
[' ']database);
$= 'query INSERT INTO user'
.'(, ,username password email) '
.'VALUE('
. "'1', '123456',user
' 1@ .user gmail com'"
;'('.