Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- *
- * @author Raul Souza Silva
- * @copyright none
- *
- */
- Class PDOConnectionFactory {
- /**
- * @var $bdType String
- * @uses is the what database you will connect
- */
- private $dbType = "mysql"; // Change to connect to others databases
- /**
- * @var $host String
- * @uses is the server you will connect
- */
- private $host = "127.0.0.1";
- /**
- * @var $username String
- * @uses the user will connect to database
- */
- private $username = "root";
- /**
- * @var $password String
- * @uses is the user's password of the database
- */
- private $password = "";
- /**
- * @var $database String
- * @uses wich data base you will connect
- */
- private $database = "estudos";
- /**
- * @var $con ObjectConnection
- * @uses this var will store the connection's object of the database
- */
- private $con = null;
- /**
- * @var $persistent boolean
- * @uses set this to true to able the persistent connection
- */
- private $persistent = false;
- public function PDOConnectionFactory($persistent=false){
- if($persistent!=false){$this->persistent = true;}
- }
- public function setDbType($type){$this->dbType = $type;}
- public function setHost($host){$this->host = $host;}
- public function setUsername($user){$this->username = $user;}
- public function setPassword($pass){$this->password = $pass;}
- public function getConnection(){
- try {
- $this->con = new PDO($this->dbType.":host=".$this->host.";dbname=".$this->database,$this->username,$this->password,array(PDO::ATTR_PERSISTENT=>$this->persistent));
- return $this->con;
- } catch(PDOException $e){
- echo "Erro: ".$e->getMessage();
- }
- }
- public function close(){
- if($this->con!=null){
- $this->con = null;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement