function DBConnect() {
$host = "localhost";
$UserID = "trangzone_main";
$passwd = "is43a";
// $host = "localhost";
// $UserID = "root";
// $passwd = "";
$link = mysql_connect($host,$UserID,$passwd) or die(mysql_error());
return $link;
}
function GetRecord($sql1) {
$DBName = "trangzone_main";
$result = mysql_db_query($DBName,$sql1);
//echo "$sql1";
return $result;
}
Class DBQuery {
var $DBName = "trangzone_main";
var $linkID;
var $sql;
var $results;
function DBQuery($l) {
$this->linkID = $l;
}
function SelectRecord($sel,$table,$where="",$order="",$group="",$limit="") {
$this->sql = "select ".$sel." from ".$table;
if ($where != "") $this->sql .= " where ".$where;
if ($order != "") $this->sql .= " order by ". $order;
if ($group != "") $this->sql .= " group by ". $group;
if ($limit != "") $this->sql .= " LIMIT ".$limit;
return $this->QueryDB();
}
function InsertRecord($table,$insert="",$values) {
$this->sql = "Insert into ".$table;
if ($insert != "") $this->sql .= " (".$insert.")";
$this->sql .= " values (".$values.")";
return $this->QueryDB();
}
function UpdateRecord($table,$update,$where) {
$this->sql = "Update ".$table." set ".$update." where ".$where;
return $this->QueryDB();
}
function DeleteRecord($table,$where) {
$this->sql = "Delete from ".$table." where ".$where;
return $this->QueryDB();
}
function QueryDB() {
$this->results = mysql_db_query($this->DBName,$this->sql,$this->linkID) or die(mysql_error($this->linkID));
return $this->results;
}
function ClrRes($res) {
return mysql_free_result($res);
}
}
/* รูปแบบนำเข้า แบบ Datetime
$dt = "2004-06-15 14:09:01";
ตัวอย่างเวลานำเข้า
$startd = $_POST['StartY'] . "-" . $_POST['StartM'] . "-" . $_POST['StartD'].date("H:i:s");
เรียกใช้งาน
ShowFullD($dt,"en","true"); ==> 15 June 2004 Time 14:09:01
ShowFullD($dt,"en","false"); ==> 15 June 2004
ShowFullD($dt,"th","true"); ==> วันที่ 15 มิถุนายน 2547 เวลา 14:09:01
ShowFullD($dt,"th","false"); ==> วันที่ 15 มิถุนายน 2547
*/
function ShowFullD($dt,$language="en",$showt="true") {
$DayName_th = array( 1 => 'จันทร์', 2 => 'อังคาร', 3 => 'พุธ',4 => 'พฤหัสบดี',5 => 'ศุกร์',6 => 'เสาร์',7 => 'อาทิตย์');
$DayName_en = array(1 => 'Monday',2 => 'Tuesday',3 => 'Wednesday',4 => 'Thursday',5 => 'Friday',6 => ' Saturday',7 => 'Sunday');
$mth = array ( '01' => 'มกราคม','02' => 'กุมภาพันธ์','03' => 'มีนาคม','04' => 'เมษายน','05' => 'พฤษภาคม','06' => 'มิถุนายน','07' => 'กรกฎาคม','08' => 'สิงหาคม','09' => 'กันยายน','10' => 'ตุลาคม','11' => 'พฤศจิกายน','12' => 'ธันวาคม' );
$men = array( '01' => 'January','02' => 'February','03' => 'March','04' => 'April','05' => 'May','06' => 'June','07' => 'July','08' => 'August','09' => 'September','10' => 'October','11' => 'November','12' => 'December');
if (strpos($dt," ")) {
list($fd,$ft)=split(" ",$dt);
list($y,$m,$d)=split("-",$fd);
}else list($y,$m,$d)=split("-",$dt);
if ($language=="th") {
$y += 543;
echo "วันที่ ".$d." ".$mth[$m]." ".$y;
if (isset($ft) && ($showt == "true")) echo "
เวลา ".$ft;
}else{
echo $d." ".$men[$m]." ".$y;
if (isset($ft) && ($showt == "true")) echo "
Time ".$ft;
}
}
function ShortDate($dt) { // 2004-06-15 14:09:01, 2004-06-15 ==> 15/06/04
list($tmpd,$tmpt) = split(" ",$dt);
list($y,$m,$d) = split("-",$tmpd);
$y = substr($y,2,2);
echo "$d/$m/$y";
}
function ThaiDate($dt) { // 2004-06-15 ==> วันอังคารที่ 15 มิถุนายน 2547
$DayName = array( 1 => 'จันทร์', 2 => 'อังคาร', 3 => 'พุธ', 4 => 'พฤหัสบดี',5 => 'ศุกร์',6 => 'เสาร์',7 => 'อาทิตย์');
$mth = array ( 1 => 'มกราคม',2 => 'กุมภาพันธ์',3 => 'มีนาคม',4 => 'เมษายน',5 => 'พฤษภาคม',6 => 'มิถุนายน',7 => 'กรกฎาคม',8 => 'สิงหาคม',9 => 'กันยายน',10 => 'ตุลาคม',11 => 'พฤศจิกายน',12 => 'ธันวาคม' );
list($y,$m,$d)=split("-",$dt);
$thisdate = getdate(mktime (0,0,0,$m,$d,$y));
$y += 543;
echo "วัน".$DayName[$thisdate['wday']]."ที่ ".$d." ".$mth[$thisdate['mon']]." ".$y;
}
function FullThaiDate($dt) { // 2004-06-15 ==> 15 มิถุนายน 2547
$mth = array ( '01' => 'มกราคม','02' => 'กุมภาพันธ์','03' => 'มีนาคม','04' => 'เมษายน','05' => 'พฤษภาคม','06' => 'มิถุนายน','07' => 'กรกฎาคม','08' => 'สิงหาคม','09' => 'กันยายน','10' => 'ตุลาคม','11' => 'พฤศจิกายน','12' => 'ธันวาคม' );
list($y,$m,$d)=split("-",$dt);
$y += 543;
$d = $d+0;
echo $d." ".$mth[$m]." ".$y;
}
function ShowMsg($msg,$link) {
echo "";
}
function ErrMsg($msg) {
echo "";
}
function CheckLogin1() {
session_start();
if (!isset($_SESSION['login']) or !isset($_SESSION['pwd'])) {
ShowMsg("คุณยังไม่ได้ Login กรุณา Login ก่อน","index.html");
}
}
function CheckLogin2() {
session_start();
if (!isset($_SESSION['login']) or !isset($_SESSION['pwd'])) {
ShowMsg("คุณยังไม่ได้ Login กรุณา Login ก่อน","../index.html");
}
}
function ChgMonth($tmp_name) {
$month_array = array ( 'มกราคม' => 'January','กุมภาพันธ์' => 'February', 'มีนาคม' => 'March','เมษายน' => 'April',
'พฤษภาคม' => 'May','มิถุนายน' => 'June','กรกฎาคม' => 'July','สิงหาคม' => 'August','กันยายน' => 'September',
'ตุลาคม' => 'October', 'พฤศจิกายน' => 'November','ธันวาคม' => 'December' );
return $month_array[$tmp_name];
}
function SplitDate($tmp_date) {
$d1 = trim(substr($tmp_date,0,strpos($tmp_date,"-")));
$d2 = trim(substr($tmp_date,strpos($tmp_date,"-") + 1,strpos($tmp_date," ") - strpos($tmp_date,"-")));
$m = trim(substr($tmp_date,strpos($tmp_date," ") + 1,strrpos($tmp_date," ") - strpos($tmp_date," ")));
$y = trim(substr($tmp_date,strrpos($tmp_date," ") + 1,4));
$tmp_array = array (0 => $d1, 1 => $d2, 2 => $m, 3 => $y);
return $tmp_array;
}
/*
function Security() {
echo "";
}
*/