Last active
June 26, 2020 09:09
-
-
Save LQ80/da604a568c71b800c54fdbb764f13e18 to your computer and use it in GitHub Desktop.
myPDO
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class myPDO { | |
var $driver = 'mysql'; | |
var $host = 'localhost'; | |
var $dbname = 'database'; | |
var $username = 'username'; | |
var $password = 'password'; | |
var $charset = 'utf8'; | |
var $stmt = ''; | |
var $result = ''; | |
function conn($driver = '', $host = '', $dbname = '', $username = '', $password = '', $charset = '') { | |
if(!empty($driver)){ | |
$this->driver = $driver; | |
} | |
if(!empty($host)){ | |
$this->host = $host; | |
} | |
if(!empty($dbname)){ | |
$this->dbname = $dbname; | |
} | |
if(!empty($username)){ | |
$this->username = $username; | |
} | |
if(!empty($password)){ | |
$this->password = $password; | |
} | |
if(!empty($charset)){ | |
$this->charset = $charset; | |
} | |
return new pdo("$this->driver:host=$this->host;dbname=$this->dbname;charset=$this->charset;", $this->username, $this->password); | |
} | |
function sql($sql='') { | |
$this->stmt = $this->conn()->prepare($sql); | |
} | |
function result($input=[], $fetch_style = PDO::FETCH_ASSOC) { | |
$this->stmt->execute($input); | |
return $this->stmt->fetchAll($fetch_style); | |
} | |
function row($input=[], $fetch_style = PDO::FETCH_ASSOC) { | |
$this->stmt->execute($input); | |
return $this->stmt->fetch($fetch_style); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment