<?
require("connect.php");
echo "Delete existing database and all table : ";
$result=mysql_drop_db($db,$connect);
if ($result) { echo "Ok"; } else { echo "Error"; }
echo "<br>Create perlphpasp database for VDO system : ";
$result=mysql_create_db($db,$connect);
if ($result) { echo "Ok"; } else { echo "Error"; }
# =======
$tb = "vdo";
$query="create table vdo (vid char(13),flag char(1))";
$result=mysql_db_query($db,$query);
insertrec("2","t4400001m0001","B","","");
insertrec("2","t4400002m0001","A","","");
insertrec("2","t4400003m0001","B","","");
insertrec("2","t4400004m0001","F","","");
insertrec("2","t4400004c0001","B","","");
insertrec("2","t4400004c0002","A","","");
insertrec("2","t4400004c0003","B","","");
insertrec("2","t4400005m0101","B","","");
insertrec("2","t4400005m0201","B","","");
insertrec("2","t4400005m0301","B","","");
tocntrec();
$tb = "story";
$query="create table story (vid8 char(8),vname char(20))";
$result=mysql_db_query($db,$query);
insertrec("2","t4400001","Batman","","");
insertrec("2","t4400002","Superman","","");
insertrec("2","t4400003","Love Z","","");
insertrec("2","t4400004","Pokemon","","");
insertrec("2","t4400005","Doramon","","");
tocntrec();
$tb = "stock";
$query="create table stock (vid11 char(11),getdate date,amt int(3))";
$result=mysql_db_query($db,$query);
insertrec("3","t4400001m00","2000-11-06",1,"");
insertrec("3","t4400002m00","2000-11-31",1,"");
insertrec("3","t4400003m00","2001-06-06",1,"");
insertrec("3","t4400004m00","2001-06-06",1,"");
insertrec("3","t4400004c00","2001-06-06",3,"");
insertrec("3","t4400005m01","2001-06-06",1,"");
insertrec("3","t4400005m02","2001-06-06",1,"");
insertrec("3","t4400005m03","2001-06-06",1,"");
tocntrec();
$tb = "borrow";
$query="create table borrow (bid char(11),bdate date,cid char(7),eid char(5))";
$result=mysql_db_query($db,$query);
insertrec("4","r4400000151","2001-11-28","c440001","e4401");
insertrec("4","r4400000152","2001-12-21","c440001","e4401");
insertrec("4","r4400000153","2001-12-22","c440002","e4402");
tocntrec();
$tb = "borrowd";
$query="create table borrowd (bid char(11),vid char(13),bflag char(1),sdate date)";
$result=mysql_db_query($db,$query);
insertrec("4","r4400000151","t4400004c0001","S","2001-12-1");
insertrec("4","r4400000151","t4400004c0002","S","2001-11-30");
insertrec("4","r4400000152","t4400001m0001","B","2001-12-28");
insertrec("4","r4400000152","t4400004c0001","F","2001-12-25");
insertrec("4","r4400000152","t4400004c0002","S","2001-12-26");
insertrec("4","r4400000152","t4400004c0003","S","2001-12-25");
insertrec("4","r4400000153","t4400005m0301","S","2001-12-26");
tocntrec();
$tb = "empl";
$query="create table empl (eid char(5),ename char(20),cryptpasswd char(13))";
$result=mysql_db_query($db,$query);
$pass = "abc";
$key = "thaiall";
$cryptpasswd = crypt($pass,$key);
insertrec("3c","e4401","Mr.Tatsanee","$cryptpasswd","");
insertrec("3c","e4402","Mr.Suwit","$cryptpasswd","");
tocntrec();
$tb = "cust";
$query="create table cust (cid char(7),cname char(20),addr char(40))";
$result=mysql_db_query($db,$query);
insertrec("3c","c440001","Ms.Pong","Yonok college lampang 52000","");
insertrec("3c","c440002","Ms.Ketsarin","Yonok college lampang 52000","");
insertrec("3c","c440003","Ms.Phimine","146 T.Sala A.Korkar Lampang 52130","");
tocntrec();
mysql_close($connect);
# == end ==
function insertrec($cntx,$x1,$x2,$x3,$x4) {
global $db,$tb;
if ($cntx=="2"){$query="insert into $tb values('$x1','$x2')";}
if ($cntx=="3"){$query="insert into $tb values('$x1','$x2',$x3)";}
if ($cntx=="3c"){$query="insert into $tb values('$x1','$x2','$x3')";}
if ($cntx=="4"){$query="insert into $tb values('$x1','$x2','$x3','$x4')";}
$result = mysql_db_query($db,$query);
if ($result) { echo "<br>$query : Ok"; } else { echo "<br>$query : Error"; }
}
function tocntrec(){
global $db,$tb;
$result = mysql_db_query($db,"select * from $tb");
$cnt=mysql_num_rows($result);
echo "<br>Total record : $cnt <hr>";
}
?>
จำนวน : 96 บรรทัด