php - data input abstraction layer? -


I have to do a custom function with a insert / edit / delete records > Database for each page without writing single questions

I have thought of moving forward in this way:

  // page.php: $ datainput = new data inputAbrace (); $ Datainput-> SetTableName = 'portal'; $ Datainput-> SetAllowedFields = Array ('name' = & gt; 'defaultvalue', 'text' =>; '', 'desc' = & gt; ''); $ Datainput-> Run (); // DataInputAbstraction.class.php: class dataInputAbracements {// & gt; Atr Public Function Run (if (Asset ($ _ POST ['Action']) and $ _POST ['Action'] == 'Insert') {$ filteredData = array_intersect_key ($ this- & gt; allowed fields , $ _pd); // $ ;- $ FilteredData to enter $ this-> Table} // & gt; if $ _POST ['action'] == 'edit' | ' Dell '}}   

Basically the action is executed () $ _POST [' Action '].

Unwanted variables with filtering Fields allowed with intersect_key attribute, after that it

INSERT $ -is-> The table name (array_keys ($ field)) creates a query (values ​​= array_values ​​($ field)) (pseudocode)

Do you think this will further Is there a better way to grow? Are there better ways or do PHP provide a similar built-in functionality?

Thanks

In my opinion, if you do not want to use anything already there, you would love to proceed about it.

I like always as abstruse as possible because it prevents you from making difficult decisions about using which service you have, for example, to handle all your data transactions, If you later change the database provider on the same thing which is for you, then your data is an abstract class.

So, I think this is a good idea. My only recommendation will be to ensure that you adhere to dry principals and keep your intangible layer very modular. The code that uses the abstract layer should know nothing about how it works. , Just provides this required data.

Hope that helps.

Comments