Why use PHP?



Using PHP scripting and MySQL™ database enables programmers to create applications
that will run on just about any computer, regardless of operating system. PHP has thousands of programming functions to facilitate
almost any task.

If the computer can run web server software, the PHP / MySQL™ application is portable
across operating systems and environments … PC, Mac, Linux, Unix, Windows, Lindows, Internet,
Intranet, etc. This means I can develop a project on my Windows PC, and send it to my friend in
Slovakia who can run it on his Linux box.

PHP / MySQL™ is most often used to create dynamic web sites. On
this web site, one script drives about 60 pages of content. Additional scripts are used here to
process form data … but that too could be done through the main script using included files.

PHP / MySQL™ projects include forums or communities, organizers,
project management tools, calendars, shopping carts, mailing lists, and all sorts of useful
applications. Source code for many open source projects is free, while advanced projects often
require a registration fee for commercial use.

Data can be exported from MySQL™ for use in spreadsheets or databases on your PC.
Similarly, data residing in existing PC spreadsheets and databases can be imported to an online
database. The portability of data opens up all sorts of uses, especially for workgroups and for
those who need to access data from both home and work.

Tips for using PHP with MySQL™

Most web hosts suck. Start your hosting experience with a proven and reliable web host that already hosts millions of domains, offers cPanel®, and regularly upgrades phpMyAdmin. If a web host offers an old
version of PHP and an old version of phpMyAdmin they
probably don’t care if the system runs at peak performance, nor whether users have current
software.

Never use a hyphen (-) in the name of a MySQL™ database, table, or column name, even if hyphens are
technically allowed. Doing so will crash your project with MySQL™ errors when when a double quoted PHP string interprets the hyphen as a minus sign.

Generally speaking, name your variables and MySQL™ components using ONLY lower case alphanumeric
characters and the underscore (_) character. Variable names and MySQL™ components should begin with a letter, not a number.
Upper case table names and field names may not be usable on other systems, depending on their
configuration.

Creating MySQL™ column
names such as “first_name” instead of “FirstName” will enhance readability and
facilitate replacing the underscore character with a space when displaying column names.

PHP reserved words

Do not use PHP reserved words or MySQL™ reserved
words
™ reserved words as the name of a PHP variable or a MySQL™ database, table, or column. Usage of reserved words
is likely to cause unexpected results, and cause you (or someone else) to waste a lot of time trying
to track down the problem.

Learn to use the define() function in order to create variables that are automatically global in
scope (available within user defined functions). Alternatively, consider creating configuration
variables as an array which can subsequently be declared as global is scope within individual, user
defined functions. Syntax for your configuration variables might use a syntax such as:

Learn to use the define() function in order to create variables that are automatically global in
scope (available within user defined functions). Alternatively, consider creating configuration
variables as an array which can subsequently be declared as global is scope within individual, user
defined functions. Syntax for your configuration variables might use a syntax such as:

$opts = array();
$opts[‘host’] = ‘localhost’;
$opts[‘user’] =
‘someone’;

Saving PHP scripts or “include files” using the
filename extension “.inc” will result in the server displaying that file as if it were a
text file (if requested directly by the web browser). Consequences can be significant if you were to
expose your database logon inside something like “db_logon.inc”.

Turning your Windows box into a WAMP PC

Don’t install the latest versions of Apache and PHP
on 64-bit Windows 7. They will appear to work on 64-bit Windows 7 but won’t play well together. Use
Apache 2.0x not 2.2. Pick a PHP version which is about
a year old. This can save you about 3 days of swearing. Presumably the same is true for 64-bit
Vista. Obscure bugs can exist in PHP’s .DLL files for the latest versions of PHP which are run largely under Linux. It takes a long
time for Windows related bugs to crop up, be reported, and be fixed.

Installing PHP and MySQL™ on a Windows PC is less intimidating than it was a few
years ago. You will learn more about PHP and MySQL™ if you install the
applications individually after visiting the Downloads page at both PHP.net scripting and MySQL.com. Due to differences between Linux and Windows file systems, you may
sometimes need your scripts to respond differently based on where they’re being run (PC vs. web
server). Consider setting a unique variable in your PC’s Apache httpd.conf file, possibly something
like ‘SetEnv WAMP 1’ which can later be evaluated in a PHP script with:

if(isset($_SERVER[‘WAMP’])){

// running on pc

}

With Apache running on a Windows PC, there may be times when it would be helpful for the script
to automatically determine whether it is being run from the WAMP development environment or
production LAMP environment. I encounter this often when a directory path on the web server is
different from the directory structure on the PC. Consider editing the Apache httpd.conf file on the
WAMP PC, adding a unique environmental variable that is unlikely to be exist on any other server.
Subsequently PHP’s $_SERVER variables can easily be checked.

In my PC’s Apache httpd.conf file, I added: SetEnv WAMP 1 and subsequently in PHP scripts I can determine the runtime location with:
if(isset($_SERVER[‘WAMP’])){ // }

If your web host allows you to alter the PHP configuration using the .htaccsss file, you can set your timezone in your .htaccess with something like SetEnv TZ America/Denver

If your web host allows you to alter the PHP configuration using the .htaccsss file, you can add custom variables to the $_SERVER array, for example SetEnv MY_DATABASE dbname would populate the PHP variable $_SERVER[‘MY_DATABASE’]

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s