multiple php scripts

Links for php scripts

Moderators: macek, egami, gesf

Post Reply
seandisanti
php-forum Fan User
php-forum Fan User
Posts: 973
Joined: Mon Oct 01, 2012 12:32 pm

Re: multiple php scripts

Post by seandisanti » Fri Mar 22, 2013 7:31 am

personally I use a file Database.php that contains a Database class. it is called in by an autoloader function in my 'functions.php' that is loaded on every page. Whenever a page needs database access, it just calls the getInstance() static method and it's all set. Here's my database class

Code: Select all

<?php
/*
 * Database class only one connection is allowed.
 */

class Database extends PDO{

    private static $instance;

    public static function getInstance() {
        if (!self::$instance) {
            
            self::$instance = new self("mysql:host=". DBHOST . ";dbname=".DB,DBUSER,DBPASSWORD);
        }
        return self::$instance;
    }



    /*
     * empty clone magic method to prevent duplication
     *
     */

    private function __clone() {
    
    }


}
 

NdotTechnologies
New php-forum User
New php-forum User
Posts: 6
Joined: Mon Mar 11, 2013 1:33 am
Contact:

Re: multiple php scripts

Post by NdotTechnologies » Mon Mar 25, 2013 1:54 am

Hire PHP Developers - Thanks for the info

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests