Created
April 26, 2018 05:50
-
-
Save relliv/97cabb4960a1e7272e682399b6795148 to your computer and use it in GitHub Desktop.
PHP PDO Basic MySQL Database Connection Class
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 Connection{ | |
| // database configuration | |
| public $db = 'testa'; | |
| public $host = 'localhost'; | |
| public $user = 'root'; | |
| public $pass = ''; | |
| // MySQL Connection Function | |
| public function MySQLConnection(){ | |
| try { | |
| $pdo = new PDO("mysql:host={$this->host}; dbname={$this->db}; charset=utf8", "{$this->user}", "{$this->pass}"); | |
| $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING ); | |
| return $pdo; | |
| } catch (PDOException $exp) { | |
| print_r($exp); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment