Appendix A. PHP Language Reference in this Appendix

only for RuBoard - do not distribute or recompile

Appendix A. PHP Language Reference in this Appendix

In this appendix

  • Basic Syntax

  • Variables and Types

  • Constants and Expressions

  • Operators

  • Program Flow Control Statements

  • User -Defined Functions

  • Classes

  • Built-In Functions

PHP is a general-purpose language. Almost all functionality is because of using function calls provided by libraries. You can extend PHP with functions you write. PHP supports algebraic form arithmetic expressions using variables, subroutine calls, general purpose I/O, and the capability to execute other programs.

PHP is very fast. In comparable projects on identical equipment, I have seen the PHP/MySQL/Linux combination outperform the ASP/SQL Server/NT 4 combination by a large margin.

EXCURSION: Speed and Data Integrity

When comparing MySQL/PHP/Linux to other server-side scripting languages in conjunction with databases, the MySQL/PHP/Linux combination will almost always be faster.

Some of this speed is because of operating system architecture. Linux can outperform NT in many areas. In some areas, NT will outperform Linux. This can be because of how each OS handles resource constraints. It is my experience that Linux handles overload more gracefully than NT.

From my experience in real-world situations, PHP is faster than ASP. When processing raw pages with commands, PHP appears to do much better in the situations I have worked with. However, feelings are not quantifiable.

I searched and found a benchmark at http://www.caucho.com/articles/benchmark.xtp. That site is attempting to show that the newer Java Server Pages can be as fast or faster than anything else available. As part of the testing, the benchmark shows that PHP is roughly nine times faster than ASP at executing script on a page. Although IIS with ASP is faster at delivering static Web pages with no scripts, the performance difference between PHP and ASP when interpreting the script is dramatic.

Some of the speed that you get from the PHP/MySQL combination is because of MySQL. This is most likely because MySQL does not support database transactions. In a database that supports transactions, the database will not be updated until the final piece of the data is in place and the transaction is committed.

NOTE

http://www.phpbuilder.com/ columns /tim20000705.php3. It shows how fast MySQL is, and gives other insightful information on its use.

The real-world implication of transactions is that if a power failure occurs in the middle of an update, the entire transaction is lost and the data in the database retains referential integrity. With MySQL, you can have pieces of the data in the database, and pieces of the data lying on the floor. In some cases, you would not know what state the database is in, and your referential integrity would be compromised.

If you carefully think through the implications of such situations, you can take steps to avoid data integrity breakdown. I have read estimates that indicated as many as 95% of the database systems installed do not need transaction technology . This is because most data is monotonic. Much of the data is not mission critical. Monotonic data enters the database as one entry in one table. Noncritical data can usually be re-entered later. A transaction is not needed in these situations.


NOTE

Our IMP application is a prime example. If the address book entry is being updated during a crash, the user can easily re-enter it after the system is up. Multiple tables are not involved, so the data can't get partially into the system.

The database could have been designed to require transactions, even for such a simple table as the address book. However, the design does not need such technology. The key here is that the system design and table design cooperate to minimize data loss in emergencies.

The bottom line is that if you need transaction technology, use a sophisticated DBMS (Data Base Management System) that can provide it. Sybase, Oracle, Informix, and Microsoft's SQL Server are among those that can provide transaction support. The price you pay is in speed and cost. You will pay thousands to support multiple users with transaction technology. However, that price can pale in comparison to the cost of recovering a damaged database.


When doing math, most of the standard algebraic formula notation is allowed. You can add ($a+$b), subtract ($a-$b), multiply ($a*$b), and divide ($a/$b). You can also take the remainder of a division. This operation is called modulus ( $a%$b ). To raise a number to a power or take the root of a number, you must use a library function. (For example, to raise a number to a power, use the pow() function. To find the square root, use the sqrt() function.)

In addition to the mathematical expressions, PHP allows you to do bitwise manipulation on the binary (base 2) values. You can bitwise or ( $a$b ), and ( $a&$b ), exclusive or ( $a^$b ), and not, also called one's complement ( ~$a ).

only for RuBoard - do not distribute or recompile


MySQL and PHP From Scratch
MySQL & PHP From Scratch
ISBN: 0789724405
EAN: 2147483647
Year: 1999
Pages: 93
Authors: Wade Maxfield

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net