NYCPHP Meetup

NYPHP.org

[nycphp-talk] Embrace Dynamic PHP

Urb LeJeune urb at e-government.com
Fri Apr 25 09:13:04 EDT 2008


>Further, I've long wanted to write a very simple set of flexible 
>helper functions for PHP newbies so they don't blow their brains out 
>with things like mysql_query("insert into blog_entries values(0, 
>"{$_POST['title']}", "{$_POST['body']}");

         I've written a DB abstraction layer in which everything is 
hash array based. The insert it method
header is:

   InsertNewRow($HTML,$_POST,$NewKey,$Table);

where $HTML is an error or progress message. There are several assumptions:

The first field in a table is named ID and is an auto-increment fields.

$_POST elements have a key that is the same as a table field name. 
$_POST[FirstName]
would map to a field named FirstName in the specified table.

There CAN be $_POST elements that do not map to any table field.

The update function header is:

   UpdateRow($HTML,$_POST,$Table,$KeyName);

$KeyName is the field name, almost always ID in my case, and must by 
undefined in
the $_POST array.

Another workhorse is:

   ExecuteQuery($HTML,$Select,$Result,$Count);

Where the $Select variables contains the desired action such as

$Select = "SELECT * FROM Messages WHERE ID = \"12345\"';

         This is then processed with:

   while($Row=mysql_fetch_assoc($Result)) {
     extract($Row);
     action code
   } # End of while($Row=mysql_fetch_assoc($Result))

         The class also has a bunch of handy methods.

         I didn't write it to make it easy for a newbe but to make it 
easy for me :-)


Urb

Dr. Urban A. LeJeune, President
E-Government.com
609-294-0320  800-204-9545
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
E-Government.com lowers you costs while increasing your expectations.





More information about the talk mailing list