<?
require("connect.php");
$tb="entstd";
$result = mysql_db_query($db,"select * from $tb");
if ($result) {
echo "Clear all records : ";
$query="delete from $tb";
} else {
echo "Create $tb : ";
$result=mysql_create_db($db,$connect);
$query="create table $tb (idstd char(13),ename char(20),esurn char(20),idtype char(4))";
}
$result=mysql_db_query($db,$query);
if ($result) { echo "Ok"; } else { echo "Error"; }
# ======
insertrecord("84470101","Mr.Tom","Somjet","1004");
insertrecord("84470102","Ms.Jane","Jnet","1004");
insertrecord("84470103","Mr.Kaew","Fukada","1003");
insertrecord("84470104","Mr.Love","Bankok","1003");
insertrecord("84470105","Ms.Idol","Thai","1001");
insertrecord("84470106","Ms.Model","Kyoko","1003");
# =======
$result = mysql_db_query($db,"select * from $tb");
$cnt= mysql_num_rows($result);
echo "<br>Restore $tb $cnt records : Ok<hr>";
$sql="select * from entstd";
$result = mysql_db_query($db,$sql);
while ($object = mysql_fetch_object($result)) {
echo $object->idstd." ".$object->ename."<br>";
}
mysql_close($connect);
# == end ==
function insertrecord($xid,$xname,$xsurn,$xtype) {
global $db,$tb;
$query="insert into $tb values('$xid','$xname','$xsurn','$xtype')";
$result = mysql_db_query($db,$query);
if ($result) { echo "<br>$query : Ok"; } else { echo "<br>$query : Error"; }
}
?>
จำนวน : 39 บรรทัด