Skip to content

Instantly share code, notes, and snippets.

@Adamwaheed
Created September 8, 2020 16:50
Show Gist options
  • Save Adamwaheed/75f1f01764e7203e629b580acd75b75c to your computer and use it in GitHub Desktop.
Save Adamwaheed/75f1f01764e7203e629b580acd75b75c to your computer and use it in GitHub Desktop.
<?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