Tuesday, May 12, 2015

Poor man pojo / popo object / entities entity generator from mysql

It's always very annoying when you have large tables and need to generate a basic pojo or popo plain old php object classes.

I've developed a simple way to just utilize mysql's information schema tables to get exactly what we need.

Here is a simple way to use a mysql query to generate what you need.


select
concat("public function get", UCASE(LEFT(column_name, 1)), SUBSTRING(column_name, 2), "(){ return $this->", LOWER(column_name), "; }" ) as getter,
concat("public function set", UCASE(LEFT(column_name, 1)), SUBSTRING(column_name, 2), "($value){ $this->", LOWER(column_name), "=$value; }" ) as setter
from
information_schema.columns
where
table_name = 'content';



Generates the following results:


 


No comments:

Post a Comment

Got a Suggestion please let us know