Uğur Gümüşhan Uğur Gümüşhan - 1 year ago 186
MySQL Question

PHP entity class generator

I am creating entity (of entity-view-controller)(in other words, model of MVC) classes which theoreticlly match the databse table I have. Is there a tool which reads mysql table and creates a model class code? (NOT on execution, a code output is required)
I expect an output like

public $columnname1;
public $columnname2;
public $columnname3;
public $columnname4;
public $columnname5;
public $columnname6;
function __construct(&$columnname1, &$columnname2){...}
function insert(&$columnname1, &$columnname2){}
function delete(&$columnname1){}

A tool which would also create insert,update and delete by id functions would help me a lot.

The tool may be free or paid.

Answer Source

PDO can fetch results into an object.

Design a class which matches your database/query structure, and use PDO::FETCH_INTO to fetch the result set into an already instantiated object. Misread the question, my bad.

To generate the class itself from the database structure, there are several projects (I haven't tested, but this came up on a very simple search).

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download