Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class MySQL{
- private $db_host;
- private $db_name;
- private $db_user;
- private $db_password;
- private $db_charset;
- public function __construct($host, $name, $user, $password, $charset)
- {
- $this->db_host = $host;
- $this->db_name = $name;
- $this->db_user = $user;
- $this->db_password = $password;
- $this->db_charset = $charset;
- }
- private function getPDO()
- {
- try {
- $pdo = new PDO('mysql:host=' . $this->db_host . ';dbname=' . $this->db_name . ';charset=' . $this->db_charset . '', '' . $this->db_user . '', '' . $this->db_password . '');
- } catch (Exception $e) {
- die('Erreur : ' . $e->getMessage());
- }
- return $pdo;
- }
- public function getQuery($statement, $fetch = null, $class_name = null)
- {
- $req = $this->getPDO->query($statement);
- if ($class_name === null) {
- $req->setFetchMode(PDO::FETCH_OBJ);
- } else {
- $req->setFetchMode(PDO::FETCH_CLASS, $class_name);
- }
- if ($fetch === fetch) {
- $datas = $req->fetch();
- } else {
- $datas = $req->fetchAll();
- }
- return $datas;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement