Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class SQLObject{
- private $_dbLink = NULL;
- private $_dbHost = NULL;
- private $_dbName = NULL;
- private $_dbUser = NULL;
- private $_dbPass = NULL;
- public function __construct($host, $name, $user, $pass){
- $this->_dbHost = $host;
- $this->_dbName = $name;
- $this->_dbUser = $user;
- $this->_dbPass = $pass;
- if(!$this->_openConnection())
- throw new Exception('La connexion a la base de données a échoué.');
- }
- public function getLink(){
- if(!is_null($this->_dbLink) OR $this->openConnection())
- return $this->_dbLink;
- else
- return false;
- }
- private function _openConnection(){
- try{
- $dsn = 'mysql:dbname=' . $this->_dbName . ';host=' . $this->_dbHost;
- $this->_dbLink = new PDO($dsn, $this->_dbUser, $this->_dbPass, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION ));
- return true;
- }
- catch(Exception $e){
- return false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement