//获取备注信息
public function _get_field() {
$model = new \Think\Model();
$controller_name = $this->CamelCaseToUnderScore(CONTROLLER_NAME);
$rs = $model->query("select `column_name`,`column_comment` from information_schema.COLUMNS WHERE TABLE_SCHEMA = '".C('DB_NAME')."' AND TABLE_NAME = '".C('DB_PREFIX').$controller_name."'");
return $rs;
}
//驼峰命名转下划线命名
public function CamelCaseToUnderScore($str){
$dstr = preg_replace_callback('/([A-Z]+)/',function($matchs){
return '_'.strtolower($matchs[0]);
},$str);
return trim(preg_replace('/_{2,}/','_',$dstr),'_');
}
原生 SQL 语句
select * from information_schema.columns where table_schema='db' table_name='user'