php导出字典

public  function promotion_list()
    {
        $sql =     "CREATE TABLE `ka_sys` (
  `id` int(11) NOT NULL AUTO_INCREMENT COMMENT ‘自增ID‘,
  `sys_name` varchar(45) CHARACTER SET utf8 NOT NULL COMMENT ‘系统中文名称‘,
  `eng_name` varchar(65) DEFAULT NULL,
  `sys_logo1` varchar(65) CHARACTER SET utf8 DEFAULT NULL COMMENT ‘大图‘,
  `sys_logo2` varchar(65) CHARACTER SET utf8 DEFAULT NULL COMMENT ‘小图‘,
  `sys_num` varchar(60) DEFAULT NULL,
  `created` int(11) NOT NULL COMMENT ‘创建时间‘,
  `updated` int(11) NOT NULL COMMENT ‘更新时间‘,
  `deleted` enum(‘1‘,‘0‘) NOT NULL DEFAULT ‘0‘ COMMENT ‘冻结‘,
  `parent_id` int(11) DEFAULT ‘0‘ COMMENT ‘系统父ID‘,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=53 DEFAULT CHARSET=latin1";
        preg_match_all("/(`.+`)(.+)(‘.+‘),/i",$sql,$out);
        echo ‘<pre>‘;
        print_r($out);
    }//
    
    public function create_database_doc()
    {
       //  /*
          header("Content-Type:   application/msword;charset=gbk");       
          header("Content-Disposition:   attachment;   filename=doc.doc");       
          header("Pragma:   no-cache");       
          header("Expires:   0");       
       
        
        // */
          
          $sql_query = "show tables;";
         
          $query     = $this->db->query($sql_query);
          $rowset    = $query->result_array();
          $tablearrs    = array();
          foreach($rowset as $key => $value)
          {
              $sql_query = "desc ". $value[‘Tables_in_ka‘];
           //   echo $sql_query;
              $query     = $this->db->query($sql_query);
              $reset     = $query->result_array();
              $this->get_notes($value[‘Tables_in_ka‘], $reset);
              $tablearrs[$key][‘tab_name‘] = $value[‘Tables_in_ka‘];
              $tablearrs[$key][‘feild_info‘] = $reset;
          }
          $output =‘‘;
          foreach ($tablearrs as $key => $value)
          {
                 $output   .=   ‘表‘.$tablearrs[$key][‘tab_name‘].PHP_EOL;
                $output    .=   ‘<table border="1" cellspacing="0" cellpadding="0"  width="90%" align="center">‘;    
                $output   .=   ‘<tr><td><strong>Field</strong></td>‘
                            . ‘<td><strong>Type</strong></td>‘
                            . ‘<td><strong>Null</strong></td>‘
                            . ‘<td><strong>Key</strong></td>‘
                            . ‘<td><strong>Default</strong></td>‘
                            . ‘<td><strong>Extra</strong></td>‘
                            . ‘<td><strong>notes</strong></td></tr>‘;   
                foreach ($tablearrs[$key][‘feild_info‘] as $ky => $val)
                {
                      $output   .=   ‘<tr><td>‘.$val[‘Field‘].‘</td>‘
                            . ‘<td>‘.$val[‘Type‘].‘</td>‘
                            . ‘<td>‘.$val[‘Null‘].‘</td>‘
                            . ‘<td>‘.$val[‘Key‘].‘</td>‘
                            . ‘<td>‘.$val[‘Default‘].‘</td>‘
                            . ‘<td>‘.$val[‘Extra‘].‘</td>‘
                            . ‘<td>‘.$val[‘notes‘].‘</td></tr>‘;
                }
                
               
                $output   .=   ‘</table>‘.PHP_EOL;
          }
         //   $output    =   mb_convert_encoding($output, "GBK","UTF-8");
          echo   $output;       
 
    }//end func create_database_doc
    
    public function get_notes($table_name,&$reset)
    {
         $sql_query = "show create table ".$table_name;
         //echo $sql_query;
         $query     = $this->db->query($sql_query);
         $rowset    = $query->result_array();
         $sql       = $rowset[0][‘Create Table‘];
         preg_match_all("/`(.+)`(.+)[‘(.*)‘],/i",$sql,$out);
     
         
         foreach ($reset as $key => $val)
         {                   
              @preg_match_all("/^(.*)\‘([^\‘]*)/i",$out[2][$key],$t_out);
              if( count($reset)-count($out[2])<=2)
              {
                  if(strpos($reset[$key][‘Field‘], ‘id‘)!==FALSE  && count($reset)-count($out[2])==1)
                       @preg_match_all("/^(.*)\‘([^\‘]*)/i",$out[2][$key-1],$t_out);
                      @$reset[$key][‘notes‘]  =$t_out[2][0];
              }
              else
              {
                    @$reset[$key][‘notes‘]  =‘‘;
              }
              
              
         }
      
         
         
    }//end func get_notes

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。