Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $servername ='localhost';
- $username = 'root';
- $password = '12345';
- $dbname = 'test';
- try {
- $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
- $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- do stuff ...
- }
- catch(PDOException $e) {
- echo $e->getMessage();
- }
- class Database {
- // DB Params
- private $host = 'localhost';
- private $db_name = "test";
- private $username = "root";
- private $password = "12345";
- private $conn;
- // DB Connect
- public function connect() {
- $this->conn = null;
- echo "connect() - ";
- try {
- $this->conn = new PDO('myqsl:host=' . $this->host . ';dbname=' . $this->db_name, $this->username, $this->password);
- $this->conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- } catch(PDOException $e) {
- echo 'HEY! Connection Error: ' . $e->getMessage();
- }
- return $this->conn;
- }
- }
Add Comment
Please, Sign In to add comment