Home  >  Article  >  Backend Development  >  PHP automatically generates class attributes based on table structure_PHP tutorial

PHP automatically generates class attributes based on table structure_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 09:44:50920browse

php automatically generates class attributes based on the table structure

php automatically generates class attributes based on the table structure

 

$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) {

// Convert underline to camel case

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

$output .=<<

 

 /**

  * {$r['column_comment']}

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

  */

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

EOF;

 }

echo '

' . $output . '
';

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1045888.htmlTechArticlephp automatically generates class attributes based on the table structure php automatically generates class attributes based on the table structure?php $table = $_GET[ 'table']; $rs = $db-queryAll(SELECT column_name,column_type,column_comment,data_...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn