Skip to content

Instantly share code, notes, and snippets.

@relliv
Created April 26, 2018 05:50
Show Gist options
  • Select an option

  • Save relliv/97cabb4960a1e7272e682399b6795148 to your computer and use it in GitHub Desktop.

Select an option

Save relliv/97cabb4960a1e7272e682399b6795148 to your computer and use it in GitHub Desktop.
PHP PDO Basic MySQL Database Connection Class
<?php
class Connection{
// database configuration
public $db = 'testa';
public $host = 'localhost';
public $user = 'root';
public $pass = '';
// MySQL Connection Function
public function MySQLConnection(){
try {
$pdo = new PDO("mysql:host={$this->host}; dbname={$this->db}; charset=utf8", "{$this->user}", "{$this->pass}");
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING );
return $pdo;
} catch (PDOException $exp) {
print_r($exp);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment