萬盛學電腦網

 萬盛學電腦網 >> 網絡編程 >> php編程 >> php根據表結構自動生成類屬性

php根據表結構自動生成類屬性

        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'");

  $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>';

copyright © 萬盛學電腦網 all rights reserved