Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*****************
- *
- * Connect to MySQL
- * Author: codekK
- *
- *****************/
- class DBconfig {
- // Define data connection
- private $conn = null;
- private static $server = "server"; // Server MySQL
- private static $user = "user"; // Username MySQL
- private static $pass = "pass"; // Password MySQL
- private static $db = "db"; // DB MySQL
- public function conn(){
- // Setting up connection
- if(!isset($this->conn)){
- try {
- $this->conn = new PDO("mysql:dbname=".self::$db.";host=".self::$server,self::$user,self::$pass);
- $this->conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- // Error
- } catch (PDOException $e){
- echo 'Connection failed: ' . $e->getMessage();
- return false;
- }
- }
- return $this->conn;
- }
- public function close(){
- unset($this->conn);
- }
- }
- ?>
Add Comment
Please, Sign In to add comment