<?php
/*
*mysql?????????
*?????????????????????????????
*
*/
classMysqlManage{
/*
*?????????????????????aid
*table?????????
*/
functioncreateTable($table){
$sql="CREATETABLEIFNOTEXISTS`$table`(`aid`INTNOTNULLprimarykey)ENGINE=InnoDB;";
M()->execute($sql);
$this->checkTable($table);
}
/*
*????????????????????????????ε????
*table?????????
*return??????????ε????
*/
functioncheckTable($table){
$sql="desc`$table`";
$info=M()->execute($sql);
return$info;
}
/*
*??????????????????????????(???????????)
*table????
*field?????
*/
functioncheckField($table??$field){
$sql='desc`$table`$field';
$info=M()->execute($sql);
return$info;
}
/*
*??????
*table????
*info??????????array
*return??????array
*/
functionaddField($table??$info){
$sql="altertable`$table`add";
$sql.=$this->filterFieldInfo();
M()->execute($sql);
$this->checkField($table??$info['name']);
}
/*
*??????
*?????????????????????
*/
functioneditField($table??$info){
$sql="altertable`$table`modify";
$sql.=$this->filterFieldInfo($info);
M()->execute($sql);
$this->checkField($table??$info['name']);
}
/*
*?????????鴦????????????????????
*info[name]???????
*info[type]???????
*info[length]??γ???
*info[isNull]??????
*info['default']???????
*info['comment']??α??
*/
privatefunctionfilterFieldInfo($info){
if(!is_array($info))
return
$newInfo=array();
$newInfo['name']=$info['name'];
$newInfo['type']=$info['type'];
switch($info['type']){
case'varchar':
case'char':
$newInfo['length']=empty($info['length'])?100:$info['length'];
$newInfo['isNull']=$info['isNull']==1?'NULL':'NOTNULL';
$newInfo['default']=empty($info['default'])?'':'DEFAULT'.$info['default'];
$newInfo['comment']=empty($info['comment'])?'':'COMMENT'.$info['comment'];
case'int':
$newInfo['length']=empty($info['length'])?7:$info['length'];
$newInfo['isNull']=$info['isNull']==1?'NULL':'NOTNULL';
$newInfo['default']=empty($info['default'])?'':'DEFAULT'.$info['default'];
$newInfo['comment']=empty($info['comment'])?'':'COMMENT'.$info['comment'];
case'text':
$newInfo['length']='';
$newInfo['isNull']=$info['isNull']==1?'NULL':'NOTNULL';
$newInfo['default']='';
$newInfo['comment']=empty($info['comment'])?'':'COMMENT'.$info['comment'];
}
$sql=$newInfo['name'].''.$newInfo['type'];
$sql.=(!empty($newInfo['length']))?($newInfo['length'])."":'';
$sql.=$newInfo['isNull'].'';
$sql.=$newInfo['default'];
$sql.=$newInfo['comment'];
return$sql;
}
/*
*??????
*???????????????????????????????false???????????
*/
functiondropField($table??$field){
$sql="altertable`$table`dropcolumn$field";
M()->execute($sql);
$this->checkField($table??$filed);
}
/*
*???????????????ε????(?????)
*/
functiongetFieldInfo($table??$field){
$info=array();
if(is_string($field)){
$this->checkField($table??$field);
}else{
foreach($fieldas$v){
$info[$v]=$this->checkField($table??$v);
}
}
return$info;
}
}
    ?t????д????????????????????????????????????????????????????????????????д????£???????????????????·