[981]PHP入門+XOOPS模組設計
<?php
//ALTER TABLE `x233_contact` DROP `pic_type`
function xoops_module_update_tad_contact(&$module, $old_version) {
 
    if(chk1())    go_update1();
    if(chk2())    go_update2();
    
    return true;
}
function chk1(){
    global $xoopsDB;
    $sql="select * from ".$xoopsDB->prefix("contact")." where `pic_type`=''";
    $result=$xoopsDB->query($sql);
    
    if(empty($result)) return false;
    return true;
}
function go_update1(){
    global $xoopsDB;
    $sql="ALTER TABLE ".$xoopsDB->prefix("contact")." DROP `pic_type`";
    $xoopsDB->queryF($sql) or redirect_header(XOOPS_URL."/modules/system/admin.php?fct=modulesadmin",30,  mysql_error());
}
function chk2(){
    global $xoopsDB;
    $sql="select `counter` from ".$xoopsDB->prefix("contact");
    $result=$xoopsDB->query($sql);
    
    if(empty($result)) return true;
    return false;
}
function go_update2(){
    global $xoopsDB;
    $sql="ALTER TABLE ".$xoopsDB->prefix("contact")." ADD `counter` SMALLINT UNSIGNED NOT NULL";
    $xoopsDB->queryF($sql) or redirect_header(XOOPS_URL."/modules/system/admin.php?fct=modulesadmin",30,  mysql_error());
}
?>