class db {
// สร้าง properties ต่างๆ
var $host;
var $user;
var $pass;
var $db_name;
var $charset;
function construct(){
$this->host = "127.0.0.1";
$this->user = "root";
$this->pass = "root";
$this->db_name = "uton";
$this->charset ="UTF8";
}
// สร้าง function สำหรับการเชือมฐานข้อมูล
function connect(){
$con = mysql_connect($this->host,$this->user,$this->pass) or die(mysql_error());
if ($con){
mysql_select_db($this->db_name) or die(mysql_error());
mysql_query("SET NAMES".$this->charset);
}
return($con);
}
}
// test connect
$db = new db();
$conn = $db->connect();
if( $con ){
echo "connect complete";
}