I know that for some of you this is not new, but for me it is and I found these functions so cool that I want to at least mention them:
Friday, December 5, 2008
DB.class
I created this class to help my self save some time writing code to access a MySQL DB.
It contains all the esential methods to connect to the DB, execute a SELECT, execute a DML (insert, update, delete) and retrieve relevant information about the last query executed (result, number of affected rows, last id inserted).
The idea is to extend this class when you want to access a table of your DB and reuse the methods without re-typing all the lines of code to connect to the DB, fetch the results, evaluate if errors were returned, etc.
///////Put code of the class here
All your now code is reduced to:
- Create a class that extends this one.
- Write your query (simple string).
- Call one of the methods of the DB class that already handles everything else (connection, execution, fetching results, building returning message of OK or ERROR).
//Put example of how to use it here
I hope you find this class useful. Any comments are welcome.
It contains all the esential methods to connect to the DB, execute a SELECT, execute a DML (insert, update, delete) and retrieve relevant information about the last query executed (result, number of affected rows, last id inserted).
The idea is to extend this class when you want to access a table of your DB and reuse the methods without re-typing all the lines of code to connect to the DB, fetch the results, evaluate if errors were returned, etc.
///////Put code of the class here
All your now code is reduced to:
- Create a class that extends this one.
- Write your query (simple string).
- Call one of the methods of the DB class that already handles everything else (connection, execution, fetching results, building returning message of OK or ERROR).
//Put example of how to use it here
I hope you find this class useful. Any comments are welcome.
Books I recommend
PHP & MySQL
HTML, XML and others -ML
- Beginning PHP5 and MySQL5 - From Novice to Professional-2e-2006-APress
- Professional Ajax Php
- Professional LAMP - Linux, Apache, MySQL, & PHP5 Web Development (2006)
- Javascript Bible 4th Edition
- O'reilly - Javascript - The Definitive Guide, 4th Edition
HTML, XML and others -ML
- OReilly XML Pocket Reference 2nd
Class Form
If there is something I "hate" of Web programming with PHP, is the constant mix of HTML with PHP and Javascrip when I have to build a screen.
I start putting the HTML code for the form (text, checkboxes, combos, buttons, etc.). Then I insert the PHP code to set initial values in the fields that -most of the time- come from the DB.
Then I plug all the possible validations I can do on the files using Javascript, such as empty files, numbers, dates, etc.
All this is very repetitive and BORING!
So, in other effort to reduce time programming the same over and over again, I created the class "Form" which:
- Has one method that builds any field you need in your form based on the arguments you pass.
- Sets all the default values for those arguments you don't pass (most of the arguments are optional).
- Builds forms with a uniform look and feel.
- Validates the inputs based on the fields you mark as "mandatory" (argument of the main method).
- Restricts the inputs to numbers if indicated.
This is saving me HOURS of development.
//Put the code here...
I start putting the HTML code for the form (text, checkboxes, combos, buttons, etc.). Then I insert the PHP code to set initial values in the fields that -most of the time- come from the DB.
Then I plug all the possible validations I can do on the files using Javascript, such as empty files, numbers, dates, etc.
All this is very repetitive and BORING!
So, in other effort to reduce time programming the same over and over again, I created the class "Form" which:
- Has one method that builds any field you need in your form based on the arguments you pass.
- Sets all the default values for those arguments you don't pass (most of the arguments are optional).
- Builds forms with a uniform look and feel.
- Validates the inputs based on the fields you mark as "mandatory" (argument of the main method).
- Restricts the inputs to numbers if indicated.
This is saving me HOURS of development.
//Put the code here...
Charts in PHP 4 without complicated installations!
You can download the library: jpgraph-1.22.1
From:
From:
Thursday, December 4, 2008
Wednesday, May 7, 2008
Subscribe to:
Posts (Atom)