Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Common CRUD functions in PHP

Tags:

php

crud

Is there a simple way to write a common function for each of the CRUD (create, retreive, update, delete) operations in PHP WITHOUT using any framework. For example I wish to have a single create function that takes the table name and field names as parameters and inserts data into a mySQL database. Another requirement is that the function should be able to support joins I.e. it should be able to insert data into multiple tables if required.

I know that these tasks could be done by using a framework but because of various reasons - too lengthy to explain here - I cannot use them.

like image 230
Vinayak Avatar asked Sep 25 '08 06:09

Vinayak


4 Answers

If you try to write such function you'll soon discover that you've just realized yet another framework.

like image 51
Sergey Stolyarov Avatar answered Sep 30 '22 20:09

Sergey Stolyarov


Of course not, that's why those frameworks exist and implement crud facilities. I'd first try to convince whomever it takes to actually use an existing framework and second, failing the above, I'd take a look at one or two of them and copy the implementation ideas. Failing all that you could take a look at http://www.phpobjectgenerator.com/

like image 23
Vinko Vrsalovic Avatar answered Sep 30 '22 20:09

Vinko Vrsalovic


Without any frameworks includes without any ORMs? Otherwise I would suggest to have a look at Doctrine or Propel.

like image 42
unexist Avatar answered Sep 30 '22 21:09

unexist


I know the way you feel.

Pork.DbObject is a simple class that you can extend your objects from. It just needs a db connection class to work.

please check out: www.schizofreend.nl/pork.dbobject/

(oh yeah, yuk @ php object generator. bloat alert! who wants to have those custom functions in every class???)

like image 27
SchizoDuckie Avatar answered Sep 30 '22 20:09

SchizoDuckie