Skip to content

Instantly share code, notes, and snippets.

@TheDutchDev
Created February 19, 2016 13:05
Show Gist options
  • Save TheDutchDev/2ebd812ba1c09911b9f3 to your computer and use it in GitHub Desktop.
Save TheDutchDev/2ebd812ba1c09911b9f3 to your computer and use it in GitHub Desktop.
PHP Database OOP
class Database
{
private
$database,
$dbhost = '', // usually localhost
$dbname = '',
$dbuser = '',
$dbpass = ''
;
public function __construct( )
{
$this->database = new mysqli( $this->dbhost, $this->dbuser, $this->dbpass, $this->dbname );
if( $this->database->connect_errno)
{
die( "Failed to connect to MySQL: (" . $this->database->connect_errno . ") " . $this->database->connect_error );
}
}
function get_connection( )
{
return $this->database;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment