Steps of PHP 5

Steps of PHP 5

& gt; PHP 5.0 released officially on July 13th is one of the most noticeable events in the developer community. PHP is currently the most commonly used programming language for building dynamic web pages with 16,251,453 domains, and 1,346,521 IP addresses, as of July 18, 2004.

PHP 5.0 has improved significantly compared to previous versions of PHP 4.x. So far, PHP 5 has been considered the most significant update in the past two years, while retaining PHP's inherent strength since PHP / FI 2.0 as speed and efficiency. (Refer to the Wikipedia history of development at Wikipedia at http://en.wikipedia.org/wiki/PHP and other PHP information on the PHP Vietnam community website at http: // www. phpvietnam.net).

Back in 1998, the introduction of Zend Engine 1 into the core of PHP Engine brought the power of PHP 4. Although PHP has attracted a large number of users, but its main limitation is not provided. More tools to build website.

Six years later, the community has seriously looked at the inherent weaknesses of PHP, making it difficult for developers to handle a number of issues. Among them, developers emphasize object-oriented programming support in PHP 4 in half-way, the MySQL extension library does not support the new MySQL 4.1 client protocol, supports patchy XML and mixed padded

PHP 5 has improved the 3 key issues (completely rewritten) and the results are really impressive. However, this is not all that good PHP 5 brought. In this article, I will cover seven key features of PHP 5. These features allow for shorter, nicer, and more dynamic code development.

Strongly supports object-oriented programming

Although the object support features have been claimed from PHP 4, however, the developer community has quickly realized their immaturity. With PHP 5, developers now have complete object-oriented programming (PHP 5 still works fine with structured programming). Some features may be listed:

A completely new object model based on the prototype is the Java model

& lt; Constructor _construct (): Creates a condition for moving classes from hierarchical to hierarchical.

_destruct (): Enables the recording of information for fault finding, data connection closure, and other resource release tasks.

Public, protected, and private methods and attributes: This allows defining the visibility of class attributes. This is important to support inheritance and packaging in object-oriented programming.

Interface: This feature is derived from the Java model to support multiple inheritance.

Abstract classes

Class hints.

Properties and static methods.

Final attributes and methods.

A variety of powerful support methods such as auto loading, reflection, exception handling, object cloning, instanceof ...

In addition, objects are now both assigning and transmitting by reference or handle instead of by value, so developers no longer have to scatter the & amp; throughout the program. These language features have also opened the way for PHP programmers to optimize the power of the pattern.

The MySQL extension library is completely rewritten

MySQL parallel database management system with PHP as the shadow, although PHP is capable of supporting many other database systems. However, while this combination brings tremendous success for both products, the backwardness of the expansion module for PHP to work with MySQL is an obstacle when it does not allow for the use of features. Extremely attractive feature of MySQL 4.1 and higher.

The PHP 5 development team has written a completely new, very powerful extensible library to support MySQL 4.1 and 5.x, called MySQLi (MySQL Improved). Features include:

Commands precompiled

The export and import parameters are limited

SSL connection

Multi-query function.

MySQLi also takes advantage of the new object-oriented programming support of PHP 5 to provide an object-oriented interface to MySQL. On top of that, the latest versions of MySQL now allow for subselects, transactions, and replication.

XML toolkit can interact

PHP 5 has improved XML support with extended XML libraries as follows:

Work together as a whole.

Standardized on a single XML library: libxml2.

Fully complies with W3 specifications.

Data processing efficiency.

& lt; Provides powerful XML processing engine.

In addition, in order to maintain the simplicity of PHP in building Web applications, a new XML library has been introduced that allows for easy reading and modification of XML documents. The SimpleXML extension module allows interaction with information contained in an XML document as if the information was an array or object, which could be used to loop through them, editing them locally by assigning them only new values ​​into variables.

If you know the format of the document, for example, when decomposing RSS files, configuration data using SimpleXML is very convenient.

If you prefer to use the DOM, you will be very interested in PHP 5's DOM extension module, which has been rewritten and improved a lot in PHP 4.

Embedded SQLITE database

The perfect connection with MySQL is a great advantage for PHP 4.x, but sometimes the web application does not need much to the ability of powerful database management. Therefore, the embedded distribution SQLite embedded database allows developers to have more tools ready to store and query data by SQL method without installing any separate database. SQLite correctly handles locking and concurrent access, two of the most prominent issues in dealing with flat file files.

SQLite is powerful enough to handle most of the storage and data manipulation needs. It supports:

Transactions:

Subqueries

Referential integrity control (triggers)

Many advanced database related features such as support for View ...

SQLite is compatible with most of the standard features of SQL92, but the latest 3.0 does not support nested, foreign-key constraints, as well as full reference control support. You can even write functions for user-defined functions in PHP and call them inside SQLite. This is the most prominent feature ever to be found in a database-related extension module in PHP.

Fault processing mechanism is brighter with Exceptions

PHP 5 provides a completely different error-checking model than PHP 4. It has an exception handling name. With exception, developers are freed from having to check the return value of all functions. Instead, you can separate the error-processing logic and place them next to the code blocks.

Exception errors are often found in object-oriented programming languages ​​such as Java and C ++. Currently, only a few PHP extensions use exceptions, but gradually this will be done synchronously. However, you can use exceptions for any of your PHP code.

Advanced SOAP implementation

SOAP is a key component of the rapidly evolving web services sector. SOAP support in PHP 4 is just average, not only because there are very few SOAP packages, but also because the most important packages written in PHP are C instead of C.

With PHP 5, we finally have an extension module for SOAP written in C. Currently, this module is largely executable, though not all of the features outlined in SOAP 1.2. In the future, this module will be improved. Currently, compared to .NET or Java, SOAP support in PHP is still in the background.

INSTALL PHP 5 WITH APACHE 2.0.X AND MYSQL ON WINXP

The software needed:
Microsoft Windows XP or Windows 2000 (I have not tested on Windows 98).
Apache 2.0.x (I use Apache 2.0.50). You can download the latest version of Apache 2.0.50 for Win32 at the address http://httpd.apache.org/
PHP 5.0 (I will install PHP 5 as an Apache module, in the way that PHP is installed for servers). You download the official version of PHP 5.0 at http://www.php.net/download or the development at http://snaps.php.net
Latest version 4.0 can be downloaded from http://dev.mysql.com/get/Downloads/MySQL-4.0/mysql-4.0.20d-win.zip/from/pick#mirrors
INSTALL APACHE 2.0
Apache 2.0.x has an automatic installer and you will not have much trouble installing this web server software on Windows. For example, to install Apache 2.0.50, just download a file named apache_2.0.50-win32-x86-no_ssl.msi and run it. By default it is installed to c: Program FilesApache GroupApache2. However, for the server management and the accompanying modules, I installed it in c: webserverApache2. You can refer to visual visual tutorial article at http://www.opensourcevn.org/javavietnam
After installation, please temporarily turn off Apache. However, you may not need to do this until you modify the Apache configuration file below.
INSTALLING PHP 5.0
Currently PHP 5 does not have an installer. You download from PHP.net file php-5.0.0-Win32.zip with a capacity of about 7.6 MB. Extract this file into the folder of your choice. For convenience, I extracted to c: webserverphp5.
After unpacking, you will see that PHP 5 has a different directory structure than PHP 4. The reason is that PHP has been rewritten almost entirely for improved performance and speed. However, you do not need to worry, all you need to do after unpacking is to find the file php.ini-recommended and perform the following steps:
- Copy it into the Apache directory mentioned above and rename it to php.ini (c: webserverApache2php.ini).
- Use plain text editor like NotePad or EditPlus to open this file.
- Find the line
extension_dir = '. /'
and replace it with
extension_dir = 'c: webserverphp5ext'
- Find the line
The extension = php_mysql.dll
and remove the ';' At the beginning of the line (applicable when you need to use the PHP functions to process data contained in MySQL).
Since the launch of PHP 5.0 Beta for the first time, developers have reported that it is set up by default not working with MySQL since the PHP 5.0 installer contains SQLite, an embedded database management system , ultra fast, full featured for small businesses. Also, the main reason is the GPL license issue. However, if you need a more advanced database management system such as MySQL, PHP 5 allows you to configure it to be ready to work. If you do not pay attention to this, you may encounter the following error:
Fatal error: Call to undefined function mysql_connect () in c: webserverwebroottexttextpatternlibtxplib_db.
phpon line 15
- Also in this php.ini file, you look to the line
session.save_path
and adjust it to
session.save_path = 'c: webserverphp5tmp'
(depending on the directory where you installed PHP5).
- Next, find the line [mail function], below the lines you will see the line
sendmail_from
Please remove the ';' At the top of the line and change your email address.
For example:
localhost@phpvietnam.net
This configuration will be used when you programmatically use the mail () function in PHP to send mail to a pre-installed email server such as QK Server.
- Go to the ext subdirectory in the PHP 5 directory (ie

For example, c: webserverphp5ext) and check if the php_mysql.dll file exists there. This is the library for PHP 5 to handle calls to the data processing functions with MySQL. If you download the official PHP 5.0, this file is definitely there. But if you are using PHP 5.0 development and export as a snapshot (http://snaps.php.net), this file may be dropped. If so, look for it in the extract folder and copy it to the ext directory.
- Copy the libmysql.dll file in the PHP 5 directory to the c: Windowssystem32 directory or the bin directory of Apache 2 (for example, c: webserverApache2bin). If this step is not taken, you may receive the error 'can not load c: webserverphp5extphp_mysql.dll'.
- Next, go to the Apache conf subdirectory and navigate to the httpd.conf file. If you install Apache 2.0.x by default, its path is c: Program FilesApache GroupApache2confhttpd.conf. In my case, it's located in c: webserverApache2confhttpd.conf. Open this file with a plain text editor and navigate to the line
#LoadModule ssl_module modules / mod_ssl.so
You add the following two lines below this line:
LoadModule php5_module 'c: /webserver/php5/php5apache2.dll'
AddType application / x-httpd-php .php
The LoadModule line will allow Apache to load the library module calling PHP 5 to perform processing tasks related to php files. You need to change php5apache2.dll file path depending on your case.
Now it is time to restart Apache 2. If there are no errors, the system tray appears as shown in Figure 1.

MYSQL SETTLEMENT 4.0
So you have configured PHP 5.0 and Apache 2.0 to run them together. You have also configured PHP 5.0's functions to query MySQL 4.0. However, you need to install more MySQL 4.0 to get enough PHP programming tools. 5. The installation of MySQL 4.0.20 is quite simple. You just download a .zip file. Extract and run the setup.exe file. MySQL software will automatically install into the default directory c: mysql. Then you go to c: mysqlbin directory to run the winmysqladmin.exe file. When running this program you will see the window as shown in Figure 2.

This window allows you to provide the name / password of the MySQL Server Administrator. Usually, this username / password pair is root / localhost, or you can leave the password blank by default. When done, click the OK button, the window disappears and the MySQL Service icon appears in the system tray, as shown in Figure 3.

As such, you already have MySQL Server running on your computer and are ready to handle queries.

CHECK INSTALLATION RESULTS
To check the installation, you perform two steps:
Go to the Apache web server root directory (Apache2htdocs), and use a plain text editor such as Notepad to create a file called phpinfo.php with the following content:
& lt;? php
echo phpinfo ();
1 & gt;
Open the browser and type http: //localhost/phpinfo.php. You will see the entire configuration of PHP 5. Please turn on the Apache Service Monitor window and you should see Figure 4.

Now you can program with PHP 5. Wish you success.

Pham Cong Dinh

PHPVietnam
pcdinh@yahoo.com
Refer:
- Changes in PHP 5:
http://www.php.net/ChangeLog-5.php
- Book of PHP5 and MySQL Bible by Wiley Publishers 2004.
- Book of PHP and MySQL for Dummies 2nd Edition 2004 by publisher Wiley

Repeater (Iterator)

Repeaters are a completely new feature in PHP 5.0. They allow you to use the for-each loop to loop through different types of data: directory listings, database result sets, and even XML documents. SPL - The standard PHP library - a set of repeaters that provides this functionality along with filtering, limiting, caching, and repeater changes.

Repeaters are a great way to manually remove all interfering code in your source code.

For example , the DirectoryIterator repeats the iteration of the directory from the spelling:

$ dir = opendir ($ path);

while (false! == ($ file = readdir ($ dir))) {

print $ filen;

closedir ($ dir);

to write:

foreach (new DirectoryIterator ($ path) as $ file) {

print $ filen;

So there is no reference pointer to any directory that is cluttered into it, nor is there any lack of clear compiler conditions that need to be checked within the loop.

In addition to the above highlights, PHP 5.0 also provides:

• Streams, wrappers and filters.

The line is the concept given in PHP 4.3, but before PHP 5.0 it was little used. The improvements introduced in PHP 5 Beta 3 allow for a file interface to read and write data using protocol-dependent objects, which are often referred to as shell names. Streams also allow for changing the flow of data through them by attaching them to the filters.

• Enumeration of code using Reflection classes.

This set of classes allows you to test classes, methods, parameters, and other things to probe the properties of an object. With them, you can easily create class probes, PHP debuggers and other tools based on gathering details about objects and functions.

Generate standard HTML code thanks to Tidy.

The Tidy extension module makes it easy to grasp the creation of valid HTML and XHTML code. Its smart separator even turns the most arbitrary code pages into pages that comply closely with the latest W3C specifications.

Better command line handling

The PHP5 command line now handles individual streams, like Perl and awk. You can specify the code to run at the beginning, in the middle, and at the end of each line in a file