Skip to content

Instantly share code, notes, and snippets.

@ziedrebhi
Last active July 16, 2017 01:01
Show Gist options
  • Save ziedrebhi/4be16ce5aead8f591380 to your computer and use it in GitHub Desktop.
Save ziedrebhi/4be16ce5aead8f591380 to your computer and use it in GitHub Desktop.
<?php
/**
* A class file to connect to database
*/
class DB_CONNECT {
var $myconn;
/**
* Function to connect with database
*/
function connect() {
// import database connection variables
require_once __DIR__ . '/db_config.php';
// Connecting to mysql database
$con = mysqli_connect(DB_SERVER, DB_USER, DB_PASSWORD,DB_DATABASE) or die(mysqli_error($con));
$this->myconn = $con;
// returing connection cursor
return $this->myconn;
}
/**
* Function to close db connection
*/
function close() {
// closing db connection
mysqli_close($myconn);
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment