首页 > 网站 > 建站经验 > 正文

php根据表!结构自动生成类属性

2019-11-02 15:48:30
字体:
来源:转载
供稿:网友

        php根据表结构自动生成类属性

  <?php

  $table = $_GET['table'];

  $rs = $db->queryAll("SELECT column_name,column_type,column_comment,data_type

  FROM information_schema.`COLUMNS` WHERE `TABLE_NAME` LIKE '$table'");

帝国影视[www.aikan.tv/special/diguoyingshi/]

  $output = '';

  foreach ($rs as $r) {

  // 下划线转驼峰

  $r['column_name'] = lcfirst(implode('', array_map('ucfirst', explode('_', $r['column_name']))));

  $output .=<<<EOF

  

  /**

  * {$r['column_comment']}

  * @var {$r['data_type']}

  */

  public ${$r['column_name']};

  EOF;

  }

  echo '<pre>' . $output . '</pre>';

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表