-
-
Save Adamwaheed/75f1f01764e7203e629b580acd75b75c to your computer and use it in GitHub Desktop.
This file contains 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 Db | |
{ | |
private $server = "mysql:host=localhost;dbname=project"; | |
private $user = "root"; | |
private $pass = ""; | |
private $options = array( | |
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, | |
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC | |
); | |
protected $con; | |
/* Function for opening connection */ | |
public function openConnection() | |
{ | |
try | |
{ | |
$this->con = new PDO($this->server, $this->user, $this->pass, $this->options); | |
return $this->con; | |
} | |
catch (PDOException $e) | |
{ | |
echo "There is some problem in connection: " . $e->getMessage(); | |
} | |
} | |
/* Function for closing connection */ | |
public function closeConnection() | |
{ | |
$this->con = null; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment