Changeset 14918


Ignore:
Timestamp:
2007/06/26 11:38:27 (17 years ago)
Author:
uehara
Message:

MySQL用auto_incrementID取得関数を改修

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/dev/data/class/SC_Query.php

    r14591 r14918  
    590590    } 
    591591     
    592     // auto_increment¤ò¼èÆÀ¤¹¤ë 
    593     function get_auto_increment($table_name){ 
    594         // ¥í¥Ã¥¯¤¹¤ë 
    595         $this->BEGIN(); 
    596          
    597         // ¼¡¤ÎIncrement¤ò¼èÆÀ 
    598         $arrRet = $this->getAll("SHOW TABLE STATUS LIKE ?", array($table_name)); 
    599         $auto_inc_no = $arrRet[0]["Auto_increment"]; 
    600          
    601         // Ãͤò¥«¥¦¥ó¥È¥¢¥Ã¥×¤·¤Æ¤ª¤¯ 
    602         $this->conn->query("ALTER TABLE $table_name AUTO_INCREMENT=?" , $auto_inc_no + 1); 
    603          
    604         // ²ò½ü¤¹¤ë 
    605         $this->COMMIT(); 
    606          
    607         return $auto_inc_no; 
    608     } 
     592    // auto_increment¤ò¼èÆÀ¤¹¤ë 
     593    function get_auto_increment($table_name){ 
     594        // ¥í¥Ã¥¯¤¹¤ë 
     595        $this->query("LOCK TABLES $table_name WRITE"); 
     596         
     597        // ¼¡¤ÎIncrement¤ò¼èÆÀ 
     598        $arrRet = $this->getAll("SHOW TABLE STATUS LIKE ?", array($table_name)); 
     599        $auto_inc_no = $arrRet[0]["Auto_increment"]; 
     600         
     601        // Ãͤò¥«¥¦¥ó¥È¥¢¥Ã¥×¤·¤Æ¤ª¤¯ 
     602        $this->conn->query("ALTER TABLE $table_name AUTO_INCREMENT=?" , $auto_inc_no + 1); 
     603         
     604        // ²ò½ü¤¹¤ë 
     605        $this->query('UNLOCK TABLES'); 
     606         
     607        return $auto_inc_no; 
     608    } 
    609609} 
    610610?> 
Note: See TracChangeset for help on using the changeset viewer.