Friday, January 2, 2009

Beginning PHP5













Beginning PHP5

What is this book about?

Beginning PHP5 is a complete tutorial in PHP5's language features and functionality, beginning with the basics and building up to the design and construction of complex data-driven Web sites. Fully functioning applications are developed through the course of the book. Other features of the book include installation guide and troubleshooting tips, introduction to relational databases, practical working examples and applications, and a detailed language reference.

Here are the new topics in this edition:

  • OOP
  • PEAR
  • GTK
  • MSI
  • CLI
  • SQLite
  • Error handling with try/catch








CakePHP Application Development













CakePHP Application Development








CodeIgniter for Rapid PHP Application Development













CodeIgniter for Rapid PHP Application Development

CodeIgniter (CI) is a powerful open-source PHP framework with a very small footprint, built for PHP coders who need a simple and elegant toolkit to create full-featured web applications. CodeIgniter is an MVC framework, similar in some ways to the Rails framework for Ruby, and is designed to enable, not overwhelm.

This book explains how to work with CodeIgniter in a clear logical way. It is not a detailed guide to the syntax of CodeIgniter, but makes an ideal complement to the existing online CodeIgniter user guide, helping you grasp the bigger picture and bringing together many ideas to get your application development started as smoothly as possible.

  • Clear, structured tutorial on working with CodeIgniter
  • Careful explanation of the basic concepts of CodeIgniter and its MVC architecture
  • Using CodeIgniter with databases, HTML forms, files, images, sessions, and email
  • Building a dynamic website quickly and easily using CodeIgniter's prepared code

Improve your PHP coding productivity with this guide to the powerful and popular CodeIgniter framework.

  • Setting up the CI package on your web server
  • Understanding the Model-View-Controller (MVC) pattern for organizing a dynamic website
  • Understanding the structure of a CI site
  • Designing better views and controllers
  • Object-oriented aspects of CI
  • Integrating databases such as MySQL and simplifying your database access
  • Making your site more robust and professional by using CI's built-in classes
  • Creating and validating HTML forms with CI form helpers
  • Handling files, images, and sessions with CI
  • Sending email from CI
  • Using CI for testing your code with error handling, unit testing, benchmarking, and profiling
  • Getting an XML-RPC server and client working
  • Generating Create, Update, Delete, and Read (C.R.U.D) entries on each database table

This book steps you through the main features of CodeIgniter in a systematic way, explaining them clearly with illustrative code examples.








Beginning PHP and PostgreSQL 8: From Novice to Professional (Beginning: From Novice to Professional)













Beginning PHP and PostgreSQL 8: From Novice to Professional (Beginning: From Novice to Professional)


Beginning PHP and PostgreSQL 8 delves into some of the most popular open source web development technologies, the PostgreSQL 8 database server and PHP 5 scripting language. You'll learn to reap the benefits of these core technologies by using them in unison to create dynamic, data-driven web applications. This is an ideal read if you are a web designer, programmer, hobbyist, or novice who wants to create applications with PHP 5 and PostgreSQL 8.







Beginning PHP and PostgreSQL E-Commerce: From Novice to Professional (Beginning, from Novice to Professional)














Beginning PHP and PostgreSQL E-Commerce: From Novice to Professional (Beginning, from Novice to Professional)

The PHP language and PostgreSQL database server have long offered an ideal blend of practicality and power for both the novice and experienced programmer alike. Yet the continued evolution of both technologies makes them better suited to drive enterprise-class applications than ever before. In Beginning PHP and PostgreSQL E-Commerce: From Novice to Professional, noted authors Cristian Darie, Emilian Balanescu, and Mihai Bucica show you how to take advantage of this powerful duo to build an e-commerce web site, guiding you step-by-step through the process of designing and developing the project.

Each chapter is devoted to a specific new feature. You'll learn how to build an online product catalog complete with pagination features, shopping cart, checkout mechanism, product search feature, product recommendations, administrative features, customer accounts, an order-management system, and more. You'll also learn how to process electronic payments by integrating several popular payment services, including PayPal, DataCash, and Authorize.net, and how to integrate the Amazon E-Commerce Service (ECS).

The book promotes good programming practices, including the separation of presentation code, business code, and data access code using a 3-tier architecture. PDO (PHP Data Objects) is used to connect to the database, and PostgreSQL functions are used to store the data logic. The Smarty templating engine is used to create the presentation layer. For a preview of what this book will teach you, take a look at the HatShop shopping cart demo.

Who This Book Is For

Beginning PHP and PostgreSQL E-Commerce: From Novice to Professional is aimed at developers looking for a tutorial approach to building a full e-commerce web site from design to deployment. However, its assumed that you have mastered the basics of PHP and have some experience working with relational databases (preferably PostgreSQL).









Debugging techniques for PHP programmers by Tyler Anderson

Introduction

There are many PHP debugging techniques that can save you countless hours when coding. An effective but basic debugging technique is to simply turn on error reporting. Another slightly more advanced technique involves using print statements, which can help pinpoint more elusive bugs by displaying what is actually going onto the screen. PHPEclipse is a Eclipse plug-in that can highlight common syntax errors and can be used in conjunction with a debugger to set breakpoints.

Setting up

To learn the concepts described in this article, you are going to need PHP, a Web server, and Eclipse. The latest version of PHP supported by the debugger extension is V5.0.3.

We need a Web server to parse the pages you create in PHP and display them to the browser. This article uses Apache2. However, any Web server will suffice.

To take advantage of some of the debugging techniques in this article, you need to install Eclipse V3.1.1 and the plug-in: PHPEclipse V1.1.8. Since Eclipse requires Java™ technology, you also need to download that.

You also need the debugger module extension for PHP. Installing it is a bit tricky. Carefully follow the instructions for installing the debugger extension. For now, comment out the lines where you are asked to load and configure the extension in PHP in the php.ini file. We’ll uncomment those lines when we’re ready to use the debugger.

See Resources for download information. Now let's move on to error messages.

Error messages

Error messages are your first line of defense as a developer. You don't want to be developing code in PHP on a server that is not configured to display error messages. However, keep in mind that when your code is debugged and ready to go live, you want to make sure error reporting is turned off because you don't want visitors to your site seeing error messages that may give them enough knowledge to exploit a weakness and hack your site.

You can also use error messages to your advantage because they display the exact line of code that threw or generated an error. This makes debugging a matter of looking at the line number shown on the browser by the generated error and checking that line number in your code. Later, you will see that the PHPEclipse plug-in aides significantly in the development and debugging process by underlining syntax errors on the fly and by marking syntax errors with a red "x" when saving your file.

Let's take a look at how to turn error reporting on in the php.ini file and set the level of error reporting. Then you'll learn how to override these settings in the Apache configuration file.

Error reporting in PHP

There are many configuration settings in the php.ini file. You should already have set up up your php.ini file and placed it in the appropriate directory, as shown in the instructions in the Install PHP and Apache2 on Linux document (see Resources). There are a couple configuration variables you should know about when debugging your PHP applications. Here they are with their default values:


display_errors = Off

error_reporting = E_ALL

You can discover the current default values of these variables by searching for them in the php.ini file. The purpose of the display_errors variable is self-evident -- it tells PHP whether or not to display errors. The default value is Off. To make your life easier in the development process, however, set this value to On by replacing Off:


display_errors = On

The error_reporting variable has a default value of E_ALL. This displays everything from bad coding practices to harmless notices to errors. E_ALL is a little too picky for my liking in the development process because it clutters the browser output by displaying notices on the screen for small things like uninitialized variables. I prefer to see the errors, any bad coding practices, but not the harmless notices. Therefore, replace the default value of error_reporting as follows:


error_reporting = E_ALL & ~E_NOTICE

Restart Apache, and you're all set. Next, you'll learn how to do the same thing on Apache.

Error reporting in the server

Depending on what Apache is doing, turning error reporting on in PHP may not work because you may have multiple PHP versions on your computer. It's sometimes hard to tell which PHP version Apache is pointing to because Apache can only look at one php.ini file. Not knowing which php.ini file Apache is using to configure itself is a security problem. However, there is a way to configure PHP variables in Apache to guarantee the setting of the correct error levels.

Also, it's good to know how to set these configuration variables on the server side to veto or pre-empt the php.ini file, providing a greater level of security.

You should already have toyed with basic configurations in the http.conf file at /conf/httpd.conf when you configured Apache.

To do the same as you just did in the php.ini file, add the following lines to your httpd.conf to override any and all php.ini files:


php_flag  display_errors        on

php_value error_reporting 2039

This overrides the flag you have set for display_errors in the php.ini file, as well as the value of error_reporting. The value 2039 stands for E_ALL & ~E_NOTICE. If you prefer E_ALL, set the value to 2047, instead. Again, make sure you restart Apache.

Next, we'll test error reporting on your server.

Testing error reporting


You will save a great deal of time if you leave error reporting enabled. Errors in PHP point you right to the error in your code. Create a simple PHP file, test.php, and define it as shown in Listing 1.

Listing 1. A simple PHP that generates an error




  1. print("The next line generates an error.
    "
    );

  2. printaline("PLEASE?");

  3. print("This will not be displayed due to the above error.");

  4. ?>



The first print() statement should display its contents to the Web browser. However, the second statement generates and displays an error to the Web page. This results in the last print() statement do nothing

5 Tips To Speed Up PHP Development by Dennis Pallett

Introduction

As PHP developers, we all like to create our PHP scripts as fast as possible, and we try to take any shortcuts that we have. In some sense we are quite lazy, and we hate doing all the grunt work. That's why I'm going to give you five tips to really speed up your PHP development, and save some serious time. If you're an experienced PHP developer, these tips will probably seem very obvious to you, so this article is geared more towards beginners.

Tip #1 - Use a good editor or IDE

Using a good editor can really save you time. If you're still stuck on using Notepad to edit your PHP scripts, switch right now. There are plenty of free alternatives around, such as PHPEdit
or EditPlus 2 (Shareware). The biggest advantage you get with a proper editor is code highlighting (automatically coloring your code). Code highlighting can help you debug your scripts, or follow code logic. Most editors support code highlighting, and if yours doesn't, then you know it's not suited for coding.

Another great advantage of using a good editor is the ability to do powerful search-and-replace operations. I know for a fact that EditPlus 2 supports regular expressions in their search-and-replace functionality, and I bet most editors do. It just makes it so much easier to replace a snippet of code. Imagine having to replace something by hand hundreds of times. Think of the time that gets wasted.

You can also use a full-blown PHP IDE (Integrated evelopment Environment). Unfortunately, there aren't many PHP IDE's, and most of them are quite steep in license fees. The best one on the market is Zend Studio, by Zend
(the company backing PHP). An IDE can really save you time, by making the debugging process easier, and some IDE's (such as Zend Studio) also include IntelliSense, which will help you with function names and such (e.g. you start typing file_get.. IntelliSense shows a dropdown that matches what you were typing. It's brilliant).

In short, use a good PHP editor or IDE, and you'll save a massive amount of time!

Tip #2 - Use a framework or skeleton

Most of your PHP scripts will probably do many of the same tasks, such as database functionality (insert, update, select, delete), and have many of the same functions. You could re-write these functions and tasks every time you start a new project, but that seems a bit pointless. Instead, you could use an existing framework or skeleton, and base your new scripts on that.

You can either use a full-blown PHP framework, like CakePHP
or the Seagull Framework, but you can also use a very simple skeleton that you create yourself. It doesn't have
to be complicated at all, and can even be just one file which contains all the functions you commonly use.

If you've already written part of your new script, you've already saved time, no matter how much or little you've already written. If you use a framework, the structure of your script has also been determined already (largely), which can also save time.

In short, you should try to re-use as much code as you can, and try to create (or download) some short of skeleton or framework to really speed up development.

Tip #3 - Don't re-invent the wheel

Continuing the previous tip, something that really speeds up development is using existing solutions. I'm not talking about a skeleton or framework, but using a full-blown script, and customizing it to your needs.

If you're going to build a CMS for your website, which is actually one of the most common things PHP developers create, then you should first look at existing scripts. There are plenty of great scripts already, and many of them are completely free, often licensed under an open source license, such as the GPL license.

A good example of this is WordPress. Originally, WordPress
is a blogging tool, but it can easily be used as a CMS for your website, and you can even extend it using template hacks, plugins or code modifications. This will save you a significant amount of time, which means you can focus your
time on other tasks.

Of course in some situations, when you have really specific needs, it won't be possibly to use an existing script, but before you start, try and find something that resembles your needs. Have a look on HotScripts and search Google. There's a big chance that it already exists.

Tip #4 - KISS (Keep It Simple Stupid)

During the development of a new script, you will probably run across many problems, and you'll have to think of a good solution. The best way is to keep the solution as simple as possible, and as soon as you notice that your code becomes 'filthy', you should consider re-doing it in another way. By filthy I mean overly complicated, and believe me, I've written plenty of filthy code myself.

You get started on some solution, but along the way, you discover more problems, and instead of taking a step back and looking at what the actual problem is, you furiously
code along. This might seem to save time, but in the long run you will only end up with thorny code, that is hard to understand.

The best way is to make everything as simple as possible. I keep everything as short as possible, and my if-statements and loops are never longer than 10-20 lines. If they become longer, I will first look if I can't do it simpler, and if that's not possible, I break it up in blocks, to make it easier to follow.

In some cases I rewrite a particular block of code 3 or 4 times. This might seem a huge waste of time, but it will save you a huge amount of time in the long run.

So in short, try to keep everything as simple as possible. You should be able to immediately understand what's happening, without having to read a huge API guide or the comments.

Tip #5 - Document your code

Another great way to speed up development is to properly document your code, especially the complicated parts. However, you shouldn't over do it. The style of comments below is ridiculous, and completely pointless:



  1. // Opening connection

  2. $linkid = mysql_connect ('localhost', 'sa', 'pass');

  3. // Selecting database

  4. mysql_select_db('mydb', $linkid);

  5. // Running a query

  6. $query = mysql_query ("SELECT * FROM bla");

  7. // etc...


  8. ?>



As you can see, the comments add no value at all. Just by quickly glancing, you can figure it everything the comments say, so the comments don't serve any purpose at all. Better would be something like this:




  1. // Get our content from database

  2. $linkid = mysql_connect ('localhost', 'sa', 'pass');

  3. mysql_select_db('mydb', $linkid);

  4. $query = mysql_query ("SELECT * FROM bla");

  5. // Below is the code for our search algorithm

  6. // This algorithm first looks for a certain keyword

  7. // and the orders it on relevancy


  8. // ... code for algorithm goes here ...


  9. // Now we must make sure that all the posts

  10. // are filtered through the sensor.

  11. // This sensor checks each post, and looks for bad stuff (tm)


  12. // ... code for sensor check ...


  13. ?>



This is already much better, because we immediately know what the purpose is a of certain code block. From there we can then figure out how the code actually works.

Even this style of commenting isn't perfect, but there isn't a "perfect" style of commenting. Each developer has his or her own style, but make sure that other developers can read your code as well. This is especially important
when you work in a team.

If you properly document your code, you will be able to understand it much easier later on, which means you won't have to spend (much) time on figuring out what the code actually does, and can immediately start writing new code.
Good documentation can really save you a good de

Conclusion

In this article I have shown you five ways to shorten your development time and being able to release faster. I must tell though you that the above tips don't always work, but even if you only use one or two shortcuts, you've already
saved precious time.

If you have any tips yourself, or would like to comment on one of the tips above, feel free to leave your comments below.

al of time.


What is PHP? by David Sklar and Adam Trachtenberg

PHP is a server-side scripting language for creating dynamic Web pages. You create pages with PHP and HTML. When a visitor opens the page, the server processes the PHP commands and then sends the results to the visitor's browser, just as with ASP or ColdFusion. Unlike ASP or ColdFusion, however, PHP is Open Source and cross-platform. PHP runs on Windows NT and many Unix versions, and it can be built as an Apache module and as a binary that can run as a CGI. When built as an Apache module, PHP is especially lightweight and speedy. Without any process creation overhead, it can return results quickly, but it doesn't require the tuning of mod_perl to keep your server's memory image small. In addition to manipulating the content of your pages, PHP can also send HTTP headers. You can set cookies, manage authentication, and redirect users. It offers excellent connectivity to many databases (and ODBC), and integration with various external libraries that let you do everything from generating PDF documents to parsing XML.

PHP goes right into your Web pages, so there's no need for a special development environment or IDE. You start a block of PHP code with or even ) The PHP engine processes everything between those tags.

PHP's language syntax is similar to C's and Perl's. You don't have to declare variables before you use them, and it's easy to create arrays and hashes (associative arrays). PHP even has some rudimentary object-oriented features, providing a helpful way to organize and encapsulate your code.

Although PHP runs fastest embedded in Apache, there are instructions on the PHP Web site for seamless setup with Microsoft IIS and Netscape Enterprise Server. If you don't already have a copy of PHP, you can download it at the official Web site. You'll also find a manual that documents all of PHP's functions and features.

Create Your Own Commands

Because PHP scripts sit inside HTML documents, you don't need a special editor to create pages. You do need to be running on a server that supports PHP, however. If you run your own server, this is easy enough to do. If an ISP serves your pages, contact your ISP's support team and ask that they install PHP for you.

For Unix systems, you'll need basic Unix skills, such as using make and a C compiler, an ANSI C compiler on your system, and a Web server.

For Windows 95/NT, you'll need one of the following servers: Microsoft Personal Web Server, Microsoft Internet Information Server 3 or 4, Apache 1.3.x, or Omni HTTPd 2.0b1.

You can find all the information you need to install and configure PHP on the PHP Web site.

Quick Intro to PHP Development by Alan Grissett

Chances are that if you’ve been around the Internet long enough, you’ve heard of server-side scripting languages such as PERL, ASP and ColdFusion. These are all popular languages that are used to add interactivity to Web sites, but one stands out from the crowd in terms of usability, power, and, yes, price: the PHP scripting language. Initially developed in 1995 by North Carolina programmer Rasmus Lerdorf, PHP has since blossomed into one of the leading open-source, cross-platform scripting languages available. This is due, in large part, to the worldwide community of coders that contributes to its development. Unlike proprietary scripting languages like ASP and ColdFusion, PHP’s source code is freely available for peer review and contributions. This is, of course, the essence of open-source software development, but why is it that PHP in particular has gained such popularity among Web developers when there are other open-source alternatives, such as good old-fashioned PERL CGI scripts? One very strong reason is that PHP, unlike PERL CGI scripts, is scalable and fast. Instead of requiring the server to start a new process in the operating system’s kernel for each new request, which uses both CPU time and memory, PHP can run as a part of the Web server itself, which saves a considerable amount of processing time when dealing with multiple requests. This decreased processing time means that PHP can be used for high-traffic sites that cannot afford to have their performance hampered by relatively slow CGI scripts.

In addition to its scalability and speed, another usability factor that sets PHP apart is its ease of use. The PHP language is considered to be a mix between C and PERL, and it draws from the best features of each parent language, while adding unique features of its own. For example, PHP code can be embedded within standard HTML documents without using additional print statements or calling separate scripts to perform the processing tasks. In practice, this allows for very flexible programming practices. Although a working knowledge of HTML is a prerequisite for PHP development, PHP’s basic functions can be learned quickly and applied to a wide range of common Webmaster-related projects, such as order forms, e-mail responses, and interactive Web pages.

Contributing to the power of the PHP language, is its native support for leading relational database platforms, including MySQL, Oracle and PostgreSQL. Platform-specific functions are built into the language for 12 databases in all. This native support for database platforms is a boon to any site that needs to track user information, store product data, or collect sales information.

Last but not least, because PHP is open-source, it is essentially free to use. Almost all professional Unix-based Web hosts offer PHP as an included option with hosting accounts. Be sure to check with your host to see if it is available to you.

This article is meant to be an introduction to the PHP language and not a tutorial, but have no fear—here are several first-rate sites that have articles that will guide you along in beginning your PHP development projects:

www.php.net
www.onlamp.com/php/
www.phpbuilder.com

Chitika

Chitika list ads

Mobile Ads