PHP khóa Table

   // Part for saving data to database
   // Updated New : Using LapKan Standard
   // Updated Date: 05/11/2012
   $tenkhunggia = $_REQUEST[‘TenKhungGia’];
   $mota = $_REQUEST[‘MoTa’];
   $nguoitao = $_REQUEST[‘NguoiTao’];
   $ngaytao = $_REQUEST[‘NgayTao’];
   $ngayhieuluc = $_REQUEST[‘NgayHieuLuc’];
   $ghichu = $_REQUEST[‘GhiChu’];
   $ghichuadmin = ‘-‘;
   include ‘..\..\..\LKSource\LKGeneral\LKDatabase.php’;
   //$sql_lock=”LOCK TABLES lkkhunggiamaster READ”;
   mysql_query(“LOCK TABLES lkkhunggiamaster WRITE”);
   $sql = “insert into lkkhunggiamaster(tenkhunggia,mota,nguoitao,ngaytao,ngayhieuluc,ghichu,ghichuAdmin) values(‘$tenkhunggia’, ‘$mota’,’$nguoitao’,’$ngaytao’,’$ngayhieuluc’, ‘$ghichu’, ‘$ghichuadmin’);”;
   $result = @mysql_query($sql);
   if ($result){
       $getid= “SELECT idm FROM `lkkhunggiamaster` ORDER BY idm DESC  LIMIT 0,1;”;
//echo $row[‘idm’];
       echo json_encode(array(‘msg’=>’Lưu dữ liệu thanh cong. Mô tả: ‘.$row[‘idm’] ));        
    //echo json_encode(array(‘success’=>true));
   } else {
    echo json_encode(array(‘msg’=>’Lưu dữ liệu bị lỗi. Mô tả: ‘.$result));
   $sql_unlock=”UNLOCK TABLES;”;

=> Khóa table lại để lấy id mới nhất được sinh ra trong database


Tagged: , , , ,

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: