Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $db = Database::connect("localhost","skata","kimonas1_test","test");
- class Database{
- private static $username;
- private static $password;
- private static $database;
- private static $url;
- private static $instance;
- private static $connection;
- private function __construct(){
- if($con = self::SQLConnect(self::$url,self::$username,self::$password) != false)
- {
- self::$connection = $con;
- echo "Connection established";
- if($db = self::selectDB(self::$database,$con) != false)
- {
- echo "Connection to database established.";
- }
- else
- {
- return false;
- }
- }
- else
- {
- return false;
- }
- }
- public static function connect($url,$password,$username,$database){
- if (!isset(self::$instance)) {
- $class = __CLASS__;
- self::$username = $username;
- self::$password = $password;
- self::$url = $url;
- self::$database = $database;
- self::$instance = new $class;
- }
- return self::$instance;
- }
- private static function SQLConnect($url,$username,$password){
- $con = mysql_connect($url,$username,$password);
- if(!$con)
- {
- return false;
- }
- else
- {
- return $con;
- }
- }
- function selectDB($database,$con){
- if(isset(self::$connection))
- {
- $sel = mysql_select_db($database,$con);
- if(!$sel)
- {
- return false;
- }
- else
- {
- return $sel;
- }
- }
- else
- {
- return false;
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement