- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
abstract class DataBaseConnection {
static public $user = "root";
static private $pass = "";
static private $host = "localhost";
static private $dbName = "example";
//this method creates connection to server and selects data base
static public function dbConnect () {
//initialize connection variables
$host = self :: $host;
$dbName = self :: $dbName;
$pass = self :: $pass;
$user = self :: $user;
// connect to server
$connection = mysql_connect ( $host, $user, $pass, TRUE ) or die ("DATA BASE CONNECTION FAIL : " . mysql_error());
// select database
mysql_select_db ( $dbName, $connection ) or die ("DATA BASE HAS NOT BEEN SELECT");
//set query encoding
mysql_query("set names utf8") or die("set names utf8 failed") ;
return $connection;
}
}
DataBaseConnection :: $user = "root";
$connection = DataBaseConnection :: dbConnect ();