so I saw how usually a model is a representation of a table in a database, as for a user table, it looks something like this:
class user_model { public $id ; public $username ; public $password ; public $email ; public function save(){ $db->query(" insert into `users` (username , email , password ) values ( '$this->username' , '$this->email' , '$this->password' ) "); } public function delete( ){ $db->query(" delete from users where id = $this->id "); } }
but this process is rather slow, and most models are the basic CRUD operation ... so I use one crud model for almost all of my controllers, for example:
class crud_model { public function save( $tbl , $data ){ $db->query(" insert into $tbl ( ".explode( ',' , array_keys($data) )." ) values ( ".explode( ',' , $data )." ) "); } public function delete( $tbl , $data ){ $db->query(" delete from $tbl where $data['column'] = $data['val'] "); } }
Please note that this is a very simplified version of my model and basically it is nothing like the source code (im using active writing in the source code and it can handle complex scripts), so ignore the syntax and technical errors.
so I want to know if there is a problem with this approach? Am I missing something?
What is the point of having many models when you can get by with one CRUD model .... it just seems like time
source share