Board index   FAQ   Search  
Register  Login
Board index PHP PHP Scripts

multiple php scripts

Links for php scripts

Moderators: macek, egami, gesf

multiple php scripts

Postby anasiya » Thu Mar 21, 2013 9:36 pm

How do you use 1 database for multiple php scripts? so i have a lot of different php scripts like user management, shopping cart, forums. I don't want my customers to have to sign-up multiple times for my website. I need to know how to do this.
_____________________
easy healthy recipes ~ slow cooker recipes ~ meals recipes
Last edited by anasiya on Mon Mar 25, 2013 3:46 pm, edited 1 time in total.
anasiya
New php-forum User
New php-forum User
 
Posts: 1
Joined: Thu Mar 07, 2013 9:54 am

Re: multiple php scripts

Postby 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() {
    
    
}


}
 
seandisanti
php-forum Fan User
php-forum Fan User
 
Posts: 838
Joined: Mon Oct 01, 2012 12:32 pm

Re: multiple php scripts

Postby NdotTechnologies » Mon Mar 25, 2013 1:54 am

Hire PHP Developers - Thanks for the info
NdotTechnologies
New php-forum User
New php-forum User
 
Posts: 6
Joined: Mon Mar 11, 2013 1:33 am


Return to PHP Scripts

Who is online

Users browsing this forum: Bing [Bot] and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.