|
|
PHP Programming
PHP / MySQL Programmers Needed
PHP / MySQL programming is one of the hottest scripting languages to be found on the Internet today. The fact that PHP code can be inserted directly alongside HTML makes the language all the more convenient for programmers to use.
Much of PHP / MySQL programming is a combination of Perl, Java and C concepts. Some features of using PHP include performing sophisticated mathematical calculations, providing network information, offering mail and regular expression capabilities, and much more.
PHP / MySQL programmer uses the strongest feature is its database interfacing capability. Connecting a database to the Internet has never been so easy. What's more, it supports many of the most popular database servers on the market, including MySQL (perhaps the most powerful database server found on the market today).
With MVI Solutions's advanced PHP and MySQL programming you will get a top-notch dynamic, database-driven Web site.
Learn More About PHP / MySQL Programming
PHP and MySQL it's common to a programmer just jump right in and start building your MySQL programming tables needed with PHP MyAdmin and not make any considerations for future database growth needed. MVI Solutions recommends that programmer follow some prudent ways to build these tables and relationships.
The following example will extend a MySQL database in the form of a PHP class. Basically, if you want to program a field to your MySQL database, the PHP class acts as a wrapper to your database and adds the field for you. Sound complex? Well, this must be done properly the programmer will add efficiencies to his program.
MVI Solutions uses PHP 4.1 and MySQL 3.23 or above. We are running a Linux Web server, but everything will also work on a Windows 2000 server with Apache/IIS.
When programming Web applications, it is tedious for the programmer to add fields to a MySQL table as a new idea appear.
The general idea is to program a PHP class that contains the SQL-structure of your MySQL database, and have another object update the tables in your database automatically.
This is the WS Document and is a class to implement a document. This extends WS Dynamic Object line, which is the object that handles mySQL communication. Now, whenever we want to add a new field to my table for this class it is simple.
What's the Magic?
Because we are programming all the table fields of my class into my object WS Dynamic Object, the programmer can list al the fields to generate an automatic load and save function. Imagine the tedious task of programming a submit form and saving the result into your MySQL database. The problem is easily programmed with these dynamic classes. The object WS Dynamic Object runs through the list of fields you have programmed in your class, and checks if this field is in the HTTP_GET_VARS or HTTP_POST_VARS array, if it is, then it loads the values to an instance of your class and runs the save() function.
How about updating records?
Well, if you program a hidden field with the name of your unique field and the unique field value as its value, then the instance of your class will be given the unique value and the correct record will be updated. If this value is -1, then a new record is inserted into the database.
We've already seen how we add fields to the WS Dynamic Object class, but how does the programmer make it work? This shouldn't be too hard to understand, simply programming the variables of the class and the add Field function. The save() algorithm that is used in form submission handling. The load() algorithm that is called in the constructor of my WS Document class. This simply runs through the record set that it fetched from the MySQL table and inputs the values into the object.
It says that the object is no longer new, and that it has loaded values - this makes sure that when the object is saved, the record set is updated and not inserted.
Here comes the tricky part -- keeping the structure defined in the object and the structure of the database and its tables in sync. The entire function, called syncTable works... believe this programmer!
Here's a basic overview of what the code does:
- Program the table if it doesn't exist.
- Get the list of fields from the table and store them in an array.
- Run through the list of fields and match the names.
- If the names match, see if the field types match (ex: int(11) == int(11) ).
- If the field types match, nothing needs to be done.
- If they don't match, update the field so they match.
- If the field name is not found, then add the field to the table.
That's it! But there are some details we left out when showing you the class WS Dynamic Object.
Here is the complete variable list of the class:
class WS Dynamic Object {
var $fields; // an array of the fields in this structure
var $newobject; // is this a new object or loaded values from db?
var $table_fields; // the database equivalent of $this->fields
var $fields_ok; // control-list during update
var $missing_fields;// a list over the fields not added to the table
var $formmode;
The class variable called $formmode.
The tricky part is to check if the field is check or not checked, especially with the save() function we use in this object. To solve this, the programmer added another method to WS Dynamic Object called add Form Mode Field.
Although the naming of the function could have been better, the functionality works, and the method used was from the WS Document class.
This simply says that the field published should be treated as a checkbox, so when we add a form to create or update an instance of WS Document.
The function formMode() runs through the array formmode, and set the value to checked if the value is 1 and sets it blank if the value is 0. When the object is saved, the reversed action makes sure that checked = 1 in your MySQL table.
MVI Solutions specializes in using PHP and MySQL to develop
dynamic Web pages. Click here to learn more about
PHP and MySQL programming.
Click here to learn how PHP has helped Yahoo!
|
|