/ Published in: PHP
Allows you to connect to different datasources. Very common to use something like this for development,staging and production deployments.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<?php /* |--------------------------- | Author: Evin Weissenberg |--------------------------- */ class Connection { public static $db = '1'; // 1=production, 2=staging, 3=development. //PRODUCTION public static $host_1 = ''; public static $username_1 = ''; public static $password_1 = ''; public static $db_name_1 = ''; public static $port_1 = ''; //STAGING public static $host_2 = ''; public static $username_2 = ''; public static $password_2 = ''; public static $db_name_2 = ''; public static $port_2 = ''; //DEVELOPMENT public static $host_3 = 'localhost'; public static $username_3 = 'root'; public static $password_3 = 'password'; public static $db_name_3 = 'my_database'; public static $port_3 = '3306'; public static function dbConnection() { if (self::$db == 1) { return true; } elseif (self::$db == 2) { return true; } elseif (self::$db == 3) { return true; } else { return false; } } } //Usage Connection::$db=3; Connection::dbConnection();
URL: http://www.evinw.com