Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Description of mysql_DB
- *
- * @author Lakicevic
- */
- class mysql_DB {
- private $host;
- private $username;
- private $password;
- private $database;
- private $conn;
- public function __construct($database, $host = 'localhost', $username = 'root', $password = '') {
- $this->host = $host;
- $this->username = $username;
- $this->password = $password;
- $this->database = $database;
- }
- public function connect(){
- $connString = 'mysql:host='.$this->host.';';
- $connString .= 'dbname = '.$this->database;
- try{
- $this->conn = new PDO($connString, $this->username, $this->password);
- }
- catch(PDOException $e){
- echo 'Error : '.$e->getMessage();
- }
- }
- public function execute($query){
- try{
- $pdo_statement = $this->conn->query($query);
- return $pdo_statement->fetchAll(PDO::FETCH_ASSOC);
- }
- catch(PDOException $e){
- echo 'Error : '.$e->getMessage();
- return false;
- }
- }
- public function __destruct() {
- $this->host = null;
- $this->username = null;
- $this->password = null;
- $this->database = null;
- $this->conn = null;
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement