Sunday, December 14, 2008

Chapter 1 in PHP tutorials for dummies - PHP Crash Course

Using PHP
To work through the examples in this chapter and the rest of the book, you need access to a web server with PHP installed.To gain the most from the examples and case studies, you should run them and try changing them.To do this, you need a testbed where you can experiment.

If PHP is not installed on your machine, you need to begin by installing it or having your system administrator install it for you.You can find instructions for doing so in Appendix A,“Installing PHP5 and MySQL5.” Everything you need to install PHP under Unix or Windows can be found on the accompanying CD-ROM.

Creating a Sample Application: Bob’s Auto Parts

One of the most common applications of any server-side scripting language is processing HTML forms.You’ll start learning PHP by implementing an order form for Bob’s Auto Parts, a fictional spare parts company.You can find all the code for the examples used in this chapter in the directory called chapter01 on the CD-ROM.

Creating the Order Form

Bob’s HTML programmer has set up an order form for the parts that Bob sells.This relatively simple order form, shown in Figure 1.1, is similar to many you have probably seen while surfing. Bob would like to be able to know what his customers ordered, work out the total prices of their orders, and determine how much sales tax is payable on the orders.

[Script will be posted later on]

Notice that the form’s action is set to the name of the PHP script that will process the customer’s order. (You’ll write this script next.) In general, the value of the action attribute is the URL that will be loaded when the user clicks the Submit button.The data the user has typed in the form will be sent to this URL via the method specified in the method attribute, either get (appended to the end of the URL) or post (sent as a separate message).

Also note the names of the form fields: tireqty, oilqty, and sparkqty.You’ll use these names again in the PHP script. Because the names will be reused, it’s important to give your form fields meaningful names that you can easily remember when you begin writing the PHP script. Some HTML editors generate field names like field23 by default.They are difficult to remember. Your life as a PHP programmer will be easier ifthe names you use reflect the data typed into the field.

You might want to consider adopting a coding standard for field names so that all field names throughout your site use the same format.This way, you can more easily remember whether, for example, you abbreviated a word in a field name or put in underscores as spaces.

Monday, December 8, 2008

Chapter 1 in PHP tutorials for dummies - PHP Crash Course

THIS CHAPTER GIVES YOU A QUICK OVERVIEW of PHP syntax and language constructs.If you are already a PHP programmer, it might fill some gaps in your knowledge. If youhave a background using C, Active Server Pages (ASP), or another programming language,it will help you get up to speed quickly.In this book, you’ll learn how to use PHP by working through lots of real-worldexamples taken from our experiences in building e-commerce sites.

Often, programmingtextbooks teach basic syntax with very simple examples.We have chosen not to do that.We recognize that often what you want to do is get something up and running, to understand how the language is used, instead of plowing through yet another syntax and function reference that’s no better than the online manual.Try the examples.Type them in or load them from the CD-ROM, change them,break them, and learn how to fix them again.This chapter begins with the example of an online product order form to show how variables, operators, and expressions are used in PHP.

It also covers variable types and operator precedence.You learn how to access form variables and manipulate them by working out the total and tax on a customer order.You then develop the online order form example by using a PHP script to validate the input data.You examine the concept of Boolean values and look at examples using if, else, the ?: operator, and the switch statement. Finally, you explore looping bywriting some PHP to generate repetitive HTML tables.

Key topics you learn in this chapter include :

1 Embedding PHP in HTML
2 Adding dynamic content
3 Accessing form variables
4 Understanding identifiers
5 Creating user-declared variables
6 Examining variable types
7 Assigning values to variables
8 Declaring and using constants
9 Understanding variable scope
10 Understanding operators and precedence
11 Evaluating expressions
12 Using variable functions
13 Making decisions with if, else, and switch
14 Taking advantage of iteration using while, do, and for loops

Saturday, December 6, 2008

First Chapter in PHP tutorials for dummies - What Is New in PHP 5.0?

You may have recently moved to PHP 5.0 from one of the PHP 4.x versions. As you would expect in a new major version, it has some significant changes.The Zend engine beneath PHP has been rewritten for this version. Major new features are as follows:

1 Better object-oriented support built around a completely new object model (see Chapter 6,“Object-Oriented PHP”)
2 Exceptions for scalable, maintainable error handling (see Chapter 7,“Exception Handling”)
3 SimpleXML for easy handling of XML data (see Chapter 33,“Connecting to Web Services with XML and SOAP”)

Other changes include moving some extensions out of the default PHP install and into
the PECL library, improving streams support, and adding SQLite.

Generally, this sites is divided into five main parts:
Part I,“Using PHP,” provides an overview of the main parts of the PHP language with examples. Each example is a real-world example used in building an e-commerce site rather than “toy” code.We kick off this section with Chapter 1,“PHP Crash Course.” If you’ve already used PHP, you can whiz through this chapter. If you are new to PHP or new to programming, you might want to spend a little more time on it. Even if you are quite familiar with PHP, you will want to read Chapter 6,“Object-Oriented PHP,” because the object-oriented functionality has changed significantly in PHP5.

Part II,“Using MySQL,” discusses the concepts and design involved in using relational database systems such as MySQL, using SQL, connecting your MySQL database to the world with PHP, and employing advanced MySQL techniques, such as security and optimization.

Part III,“E-commerce and Security,” covers some of the general issues involved in developing an e-commerce site using any language.The most important of these issues is security.We then discuss how you can use PHP and MySQL to authenticate your users and securely gather, transmit, and store data.

Part IV,“Advanced PHP Techniques,” offers detailed coverage of some of the major built-in functions in PHP.We have selected groups of functions that are likely to be useful when building an e-commerce site.You will learn about interaction with the server, interaction with the network, image generation, date and time manipulation, and session variables.

Part V,“Building Practical PHP and MySQL Projects,” is our favorite section. It deals with practical real-world issues such as managing large projects and debugging, and provides sample projects that demonstrate the power and versatility of PHP and MySQL.

We will discover all these chapter in next posting..

First Chapter in PHP tutorials for dummies - PHP’s Attributes

Some of PHP’s main competitors are Perl, Microsoft ASP.NET, JavaServer Pages (JSP), and ColdFusion. In comparison to these products, PHP has many strengths, including the following:

1 High performance
2 Interfaces to many different database systems
3 Built-in libraries for many common web tasks
4 Low cost
5 Ease of learning and use
6 Strong object-oriented support
7 Portability
8 Availability of source code
9 Availability of support

A more detailed discussion of these strengths follows.


Performance
PHP is very efficient. Using a single inexpensive server, you can serve millions of hits per day. If you use large numbers of commodity servers, your capacity is effectively unlimited. Benchmarks published by Zend Technologies (http://www.zend.com) show PHP outperforming its competition.


Database Integration
PHP has native connections available to many database systems. In addition to MySQL, you can directly connect to PostgreSQL, mSQL, Oracle, dbm, FilePro, Hyperwave, Informix, InterBase, and Sybase databases, among others. PHP 5 also has a built-in SQL interface to a flat file, called SQLite. Using the Open Database Connectivity Standard (ODBC), you can connect to any database that provides an ODBC driver.This includes Microsoft products and many others.


Built-in Libraries
Because PHP was designed for use on the Web, it has many built-in functions for performing many useful web-related tasks.You can generate GIF images on the fly, connect to web services and other network services, parse XML, send email, work with cookies, and generate PDF documents, all with just a few lines of code.


Cost
PHP is free.You can download the latest version at any time from http://www.php.net for no charge.


Ease of Learning PHP
The syntax of PHP is based on other programming languages, primarily C and Perl. If you already know C or Perl, or a C-like language such as C++ or Java, you will be productive using PHP almost immediately.


Object-Oriented Support
PHP version 5 has well-designed object-oriented features. If you learned to program in Java or C++, you will find the features (and generally the syntax) that you expect, such as inheritance, private and protected attributes and methods, abstract classes and methods, interfaces, constructors, and destructors.You will even find some less common features such as built-in iteration behavior. Some of this functionality was available in PHP versions 3 and 4, but the object-oriented support in version 5 is much more complete.

Portability
PHP is available for many different operating systems.You can write PHP code on free Unix-like operating systems such as Linux and FreeBSD, commercial Unix versions such as Solaris and IRIX, or on different versions of Microsoft Windows. Well-written code will usually work without modification on a different system running PHP.


Source Code
You have access to PHP’s source code.With PHP, unlike commercial, closed-source products, if you want to modify something or add to the language, you are free to do so. You do not need to wait for the manufacturer to release patches.You also don’t need to worry about the manufacturer going out of business or deciding to stop supporting a product.


Availability of Support
Zend Technologies (www.zend.com), the company behind the engine that powers PHP, funds its PHP development by offering support and related software on a commercial basis.


For next lesson in PHP tutorials for dummies, we will learn about What Is New in PHP 5.0?

First Chapter in PHP tutorials for dummies - What Is PHP?

PHP is a server-side scripting language designed specifically for the Web.Within an HTML page, you can embed PHP code that will be executed each time the page is visited. Your PHP code is interpreted at the web server and generates HTML or other output that the visitor will see.

PHP was conceived in 1994 and was originally the work of one man, Rasmus Lerdorf. It was adopted by other talented people and has gone through four major rewrites to bring us the broad, mature product we see today. As of August 2004, it was installed on more than 17 million domains worldwide, and this number is growing rapidly.

You can see the current number at http://www.php.net/usage.php

Introduction 1
PHP is an Open Source product, which means you have access to the source code and can use, alter, and redistribute it all without charge. PHP originally stood for Personal Home Page but was changed in line with the GNU recursive naming convention (GNU = Gnu’s Not Unix) and now stands for PHP Hypertext Preprocessor.

The current major version of PHP is 5.This version has seen a complete rewrite of the underlying Zend engine and some major improvements to the language. The home page for PHP is available at http://www.php.net/ The home page for Zend Technologies is http://www.zend.com/