Tuesday, February 26, 2008

Planning Your Web Database Application

Before you ever put finger to keyboard to write a PHP program, you need to plan your Web database application. This is possibly the most important step in developing your application. It’s painful to discover, especially just after you finish the last program for your application, that you left something out and have to start over from the beginning. It’s also hard on your computer (and your foot) when you take out your frustrations by drop-kicking it across the room.
Good planning prevents such painful backtracking. In addition, it keeps you focused on the functionality of your application, thus preventing you from writing pieces for the application that do really cool things but turn out to have no real purpose in the finished application. And if more than one person is working on your application, planning ensures that all the pieces will fit together in the end.

Monday, February 25, 2008

Testing whether mySQL work

After you know that PHP is running okay, you can test whether you can access MySQL by using PHP. Just follow these steps:
  • Create the following file somewhere in your Web space with the name mysql_up.php. You can download the file from http://mihd.net/i5pmy9
  • The following lines 9, 10, and 11 of the program need to be changed:
$host=”host”;
$user=”mysqlaccount”;
$password=”mysqlpassword”;
  • Change host to the name of the computer where MySQL is installed —for example, databasehost.mycompany.com. If the MySQL database is on the same computer as your Web site, you can use localhost as the hostname.
  • Change mysqlaccountname and mysqlpassword to the appropriate values. An account named root is installed when MySQL is installed, which may or may not have a password. If your MySQL account doesn’t require a password, type nothing between the quotes, as follows:
$password=””;
  • Point your browser at mysql_up.php. You should see a table with a long list of variable names and values. You don’t want to see an error message or a warning message. Don’t worry about the contents of the table. It’s only important that the table is displayed so that you know your connection to MySQL is working correctly. If no error or warning messages are displayed, MySQL is working fine. If you see an error or a warning message, you need to fix the problem that’s causing the message.
The following is a common error message:

MySQL Connection Failed: Access denied for user:
‘user73@localhost’ (Using password: YES)

This message means that MySQL did not accept your MySQL account number or your MySQL password. Notice that the message reads YES for Using password but doesn’t show the actual password that you tried for security reasons. If you tried with a blank password, the message would read NO. If you receive an error message, double-check your account number and password. Remember that this is your MySQL account number — not your account number to log on to the computer. If you can’t connect with the account number and password that you have, you might need to contact the IT department or the Web hosting company that gave you the account number.

How to test whether PHP is working?

To test whether PHP is installed and working, follow these steps:
  • Find the directory in which your PHP programs need to be saved. This directory and the subdirectories under it are your Web space. Apache calls this directory the document root. The default Web space for Apache is htdocs in the directory where Apache is installed. For IIS, it’s Inetpub\wwwroot. In Linux, it might be /var/www/html. The Web space can be set to a different directory by configuring the Web server (see Appendix C). If you’re using a Web hosting company, the staff will supply the directory name.
  • Create the following file somewhere in your Web space with the name test.php. Download the PHP file in http://mihd.net/4edokm

The file must be saved in your Web space for the Web server to find it.
    • Point your browser at the test.php file created in Step 1. That is, type the name of your Web server into the browser address window, followed by the name of the file (for example, www.myfinecompany.com/test.php). If your Web server, PHP, and the test.php file are on the same computer that you’re testing from, you can type localhost/test.hp. For the file to be processed by PHP, you need to access the file through the Web server — not by choosing FileOpen from your Web browser menu.
You should see the following in the Web browser:

This is an HTML line
This is a PHP line

Below these lines, you should see a large table that shows all the information associated with PHP on your system. It shows PHP information, pathnames and filenames, variable values, and the status of various options. The table is produced by the phpinfo() line in the test script. Anytime that you have a question about the settings for PHP, you can use the phpinfo() statement to display this table and check a setting.
  • Check the PHP values for the settings you need. For instance, you need MySQL support enabled. Looking through the listing, find the section for MySQL and make sure that MySQL support is On. PHP has many settings that can be changed. Various PHP settings are discussed throughout the book in the appropriate sections.
  • Change values if necessary. The general settings for PHP are stored in a file named php.ini. If you installed PHP yourself, you can edit php.ini and change settings. If your Web site is located on a company computer or a Web hosting company computer, you may not have access to php.ini to change settings. You can request the PHP administrator to change settings. For some settings, you can temporarily change a setting with a statement in your PHP program, but not all settings can be changed in a program.

Friday, February 22, 2008

Understanding PHP/MySQL functions

PHP can communicate with any version of MySQL. However, PHP needs to be installed differently, depending on which version of MySQL you’re using. PHP provides one set of functions (mysql functions) that communicate with MySQL 4.0 or earlier and a different set of functions (mysqli functions) that communicate with MySQL 4.1 or later.

The mysql functions, which communicate with earlier versions of MySQL, can also communicate with the later versions of MySQL, but you may not be able to use some of the newer, advanced features that were added to MySQL in the later versions. The mysqli functions, which can take advantage of all the MySQL features, are available only with PHP 5 or later.

The programs in this blog, including the test programs in this section, use MySQL 5.0 and the mysqli functions. If you’re using PHP 4, you need to change the programs to use the mysql functions, rather than the mysqli functions. The functions are similar, but some have slight changes in syntax. Versions of the programs that will run with PHP 4 are available for download at my Web site (janet.valade.com).
You might see an error message similar to the following:

Fatal error: Call to undefined function mysql_connect()

The message means that you’re using a mysql function in your program, but the mysql functions are not enabled. MySQL support might not be enabled at all or mysqli support might be enabled instead of mysql support.

Testing Preparation

Suppose you believe that PHP and MySQL are available for you to use, for one of the following reasons:
  • The IT department at your company or your client company gave you all the information that you asked for and told you that you’re good to go.
  • The Web hosting company gave you all the information that you need and told you that you’re good to go.
  • You followed all the instructions and installed PHP and MySQL yourself.
Now you need to test to make sure that PHP and MySQL are working correctly.

Installing PHP

After you install MySQL, you’re ready to install PHP. As I mention earlier, you must install MySQL before you install PHP because you may need to provide the path to the MySQL software when you install PHP. If PHP isn’t compiled with MySQL support when it is installed, it won’t communicate with MySQL.

Before you install PHP, check whether it’s already installed. For instance, some Linux and Mac distributions automatically install PHP. To see whether PHP is installed, search your disk for any PHP files:
  • _ Linux/Unix/Mac: Type the following: find / -name “php*”
  • _ Windows: Use the Find feature (choose StartFind) to search for php*.
If you find PHP files, PHP is already installed, and you might not need to reinstall it. For instance, even if you installed MySQL yourself after PHP was installed, you might have installed it in the location where PHP is expecting it. Better safe than sorry, however: Perform the testing that I describe in the next section to see whether MySQL and PHP are working correctly together.

If you don’t find any PHP files, PHP is not installed. To install PHP, you need access to the Web server for your site. For instance, when you install PHP with Apache, you need to edit the Apache configuration file. All the information and software that you need is provided on the PHP Web site (www.php.net).

Sunday, February 17, 2008

Installing MySQL

After setting up the computer and installing the Web server, you’re ready to install MySQL. You need to install MySQL before installing PHP because you may need to provide the path to the MySQL software when you install PHP.

But before installing MySQL, be sure that you actually need to install it. It might already be running on your computer, or it might be installed but not running. For instance, many Linux distributions automatically install MySQL.
Here’s how to check whether MySQL is currently running:
  • Linux/Unix/Mac: At the command line, type the following: ps –ax ,The output should be a list of programs. Some operating systems (usually flavors of Unix) have different options for the ps command. If the preceding does not produce a list of programs that are running, type man ps to see which options you need to use. In the list of programs that appears, look for one called mysqld.
  • Windows: If MySQL is running, it will be running as a service. To check this, choose StartControl PanelAdministrative ToolsServices and scroll down the alphabetical list of services. If MySQL is installed as a service, it will appear in the list. If it’s currently running, its status displays Started.
Even if MySQL isn’t currently running, it might be installed but just not started.
Here’s how to check to see whether MySQL is installed on your computer:
  • Linux/Unix/Mac: Type the following: find / -name “mysql*” If a directory named mysql is found, MySQL has been installed.
  • Windows: If you did not find MySQL in the list of current services, look for a MySQL directory or files. You can search at StartSearch. The default installation directory is C:\Program Files\MySQL\MySQL Server version number for recent versions or C:\mysql for older versions. If you found MySQL in the service list, as described, but it is not started, you can start it by highlighting MySQL in the service list and clicking Start the Service in the left panel.
If you find MySQL on your computer but did not find it in the list of running programs (Linux/Unix/Mac) or the list of current services (Windows), here’s how to start it:
  • Linux/Unix/Mac:
    • Change to the directory mysql/bin. This is the directory that you should have found when you were checking whether MySQL was installed.
    • Type safe_mysqld & When this command finishes, the prompt is displayed.
    • Check that the MySQL server started by typing ps -ax. In the list of programs that appears, look for one called mysqld.
  • Windows:
    • Open a Command Prompt window. In Windows XP, choose Start>All ProgramsAccessories Command Prompt.
    • Change to the folder where MySQL is installed. For example, type cd C:\Program Files\MySQL\MySQL Server 5.0. Your cursor is now located in the MySQL folder.
    • Change to the bin subfolder by typing cd bin. Your cursor is now located in the bin subfolder.
    • Start the MySQL Server by typing mysqld—install.
The MySQL server starts as a Windows service. You can check the installation by going to the service list, as described previously, and making sure that MySQL now appears in the service list and its status is Started.

If MySQL isn’t installed on your computer, you need to download it and install it from www.mysql.com. The Web site provides all the information and software that you need.

Installing the Web server

After you set up the computer, you need to decide which Web server to install.
The answer is almost always Apache. Apache offers the following advantages:
  • It’s free. What else do I need to say?
  • It runs on a variety of operating systems. Apache runs on Windows, Linux, Mac OS, FreeBSD, and most varieties of Unix.
  • It’s popular. Approximately 60 percent of Web sites on the Internet use Apache, according to surveys at news.netcraft.com/archives/web_ server_survey.html and www.securityspace.com/s_survey/ data/. This wouldn’t be true if it didn’t work well. Also, this means that a large group of users can provide help.
  • It’s reliable. After Apache is up and running, it should run as long as your computer runs. Emergency problems with Apache are rare.
  • It’s customizable. The open source license allows programmers to modify the Apache software, adding or modifying modules as needed to fit their own environment.
  • It’s secure. Free software is available that runs with Apache to make it into an SSL (Secure Sockets Layer) server. Security is an essential issue if you’re using the site for e-commerce.
Apache is automatically installed when you install most Linux distributions. All recent Macs come with Apache installed. For most other Unix flavors, you have to download the Apache source code and compile it yourself, although some binaries (programs that are already compiled for specific operating systems) are available. For Windows, Apache provides an installer that asks you questions and installs and configures Apache for you. For a public Web site, you should run Windows NT/2000/XP, although Apache also runs on Windows 95/98/Me.

(The Apache Web site (httpd.apache.org) provides information, software downloads, extensive documentation that is improving all the time, and installation instructions for various operating systems. Other Web servers are available. Microsoft offers IIS (Internet Information Server), which is the second most popular Web server on the Internet with approximately 27 percent of Web sites. Sun offers a Web server, which serves less than 3 percent of the Internet. Other Web servers are available, but they have even smaller user bases.

A little bit about domain names

Every Web site needs a unique address on the Web. The unique address used by computers to locate a Web site is the IP address, which is a series of four numbers between 0 and 255, separated by dots — for example, 172.17.204.2 or 192.163.2.33.

Because IP addresses are made up of numbers and dots, they’re not easy to remember. Fortunately, most IP addresses have an associated name that’s much easier to remember, such as amazon.com, www.irs.gov, or mycompany.com. A name that’s an address for a Web site is a domain name. A domain can be one computer or many connected computers. When a domain refers to several computers, each computer in the domain can have its own name. A name that includes an individual computer name, such as thor.mycompany.com, identifies a subdomain.

Each domain name must be unique in order to serve as an address. Consequently, a system of registering domain names ensures that no two locations use the same domain name. Anyone can register any domain name as long as the name isn’t already taken. You can register a domain name on the Web. First, you test your potential domain name to find out whether it’s available. If it’s available, you register it in your name or a company name and pay the fee. The name is then yours to use, and no one else can use it. The standard fee for domain name registration is $35 per year.

You should never pay more, but bargains are often available. Many Web sites provide the ability to register a domain name, including the Web sites of many Web hosting companies. A search at Google (www.google.com) for register domain name results in more than 85 million hits. Shop around to be sure that you find the lowest price. Also, many Web sites allow you to enter a domain name and see whom it is registered to. These Web sites do a domain name database search using a tool called whois. A search at Google for domain name whois results in more than 17 million hits. A couple of places where you can do a whois search are Allwhois.com (www.allwhois.com) and BetterWhois.com (www.betterwhois.com).

Wednesday, February 13, 2008

Setting up the computer

Your first decision is to choose which hardware platform and operating system to use. In most cases, you’ll choose a PC with either Linux or Windows as the operating system. Here are some advantages and disadvantages of these two operating systems:
  • Linux: Linux is open source, so it’s free. It also has advantages for use as a Web server: It runs for long periods without needing to be rebooted; and Apache, the most popular Web server, runs better on Linux than Windows. Running Linux on a PC is the lowest cost option. The disadvantage of running Linux is that many people find Linux more difficult to install, configure, administer, and install software on than Windows, although Linux is getting easier to install every day.
  • Windows: Unlike Linux, Windows is not free. However, most people feel that Windows is easier to use, and because it’s widely used, many people can help you if you have problems. If you plan a public Web site, with users accessing your Web site from the WWW, you need Windows 2000 or later.
I assume that you’re buying a computer with the operating system and software installed, ready to use. It’s easier to find a computer that comes with Windows installed on it than with Linux, but Linux computers are available. For instance, at this time, Dell, IBM, and Hewlett-Packard offer computers with Linux installed.

If you’re building your own hardware, you need more information than I have room to provide in this book. If you have the hardware and plan to install an operating system, Windows is easier to install, but Linux is getting easier all the time. You can install Linux from a CD, like Windows, but you often must provide information or make decisions that require more knowledge about your system. If you already know how to perform system administration tasks (such as installing software and making backups) in Windows or in Linux, the fastest solution is to use the operating system that you already know.

For using PHP and MySQL, you should seriously consider Linux. PHP is a project of the Apache Software Foundation, so it runs best with the Apache server. And Apache runs better on Linux than on Windows. Therefore, if all other things are equal and the computer is mainly for running a Web site with a Web database application, Linux is well suited for your purposes.
Other solutions besides a PC with Windows or Linux are available, but they’re less popular:
  • Unix-based: Other free, Unix-based operating systems are available for PCs, such as FreeBSD (which some people prefer to Linux) or a version of Solaris provided by Sun for free download.
  • Mac: Mac computers can be used as Web servers. Most newer Macs come with PHP installed. Installing PHP and MySQL on Mac OS X is fairly simple. There are fewer Mac users, however, so it can be difficult to find help when you need it. One good site is www.phpmac.com.
Your computer must be connected to the Internet. In most cases, you obtain an account from an Internet service provider (ISP). When you obtain an account from the ISP, be sure to discuss the type of use you intend. A simple user connection to the Internet is sufficient to transfer Web page files from your development computer to a Web hosting company. However, if you plan for users to access your Web site from the WWW, you need an Internet connection with more resources.

Setting up and running a Web site on your local computer

If you’re starting a Web site from scratch, you need to understand the Web site software fairly well. You have to make several decisions regarding hardware and software. You have to install a Web server, PHP, and MySQL — as well as maintain, administer, and update the system yourself. Taking this route, rather than using a Web site provided by others, requires more work and more knowledge. The advantage is that you have total control over the Web development environment.

You may want to set up a Web site on your personal computer to be a public Web site, accessed from the World Wide Web. Or you may want to set up a Web site on your personal computer where you can develop your Web site before transferring the Web page files to your work computer or a Web hosting company. These two types of use require different Internet connections, as described in Step 1 next.

Here are the general steps that lead to your dynamic Web site (I explain these steps in more detail in the next few sections):
  1. Set up the computer.
  2. Install the Web server.
  3. Install MySQL.
  4. Install PHP.
If you’re starting from scratch, with nothing but an empty space where the computer will go, start at Step 1. If you already have a running computer but no Web software, start at Step 2. Or if you have an existing Web site that does not have PHP and MySQL installed, start with Step 3.

How to pick a web hosting?

A Web hosting company provides everything that you need to put up a Web site, including the computer space and all the Web site software. You just create the files for your Web pages and move them to a location specified by the Web hosting company.

About a gazillion companies offer Web hosting services. Most charge a monthly fee (often quite small), and some are even free. (Most, but not all, of the free ones require you to display advertising.) Usually, the monthly fee varies depending on the resources provided for your Web site. For instance, a Web site with 25Mb of disk space for your Web page files costs less than a Web site with 100Mb of disk space.
When looking for a place to host your Web site, make sure that the Web hosting company offers the following:
  • PHP and MySQL: Not all companies provide these tools. You might have to pay more for a site with access to PHP and MySQL; sometimes you have to pay an additional fee for MySQL databases.
  • A recent version of PHP: Sometimes the PHP versions offered aren’t the most recent versions. As of this writing, PHP 6 is close to being released. However, you may have trouble finding a Web hosting company that offers PHP 6. In fact, you may find that most Web hosting companies still offer PHP 4, although I hope that will change over time. It is worth the time to find a Web hosting company that offers at least PHP 5, if not PHP 6. Some Web hosting companies offer PHP 4 but have PHP 5 or 6 available for customers who request it.
Other considerations when choosing a Web hosting company are
  • Reliability: You need a Web hosting company that you can depend on —one that won’t go broke and disappear tomorrow, and one that isn’t running on old computers, held together by chewing gum and baling wire, with more downtime than uptime.
  • Speed: Web pages that download slowly are a problem because users will get impatient and go elsewhere. Slow pages could be a result of a Web hosting company that started its business on a shoestring and has a shortage of good equipment — or the Web hosting company might be so successful that its equipment is overwhelmed by new customers. Either way, Web hosting companies that deliver Web pages too slowly are unacceptable.
  • Technical support: Some Web hosting companies have no one available to answer questions or troubleshoot problems. Technical support is often provided only through e-mail, which can be acceptable if the response time is short. Sometimes you can test the quality of the company’s support by calling the tech support number, or test the e-mail response time by sending an e-mail.
  • The domain name: Each Web site has a domain name that Web browsers use to find the site on the Web. Each domain name is registered for a small yearly fee so that only one Web site can use it. Some Web hosting companies allow you to use a domain name that you have registered independently of the Web hosting company, some assist you in registering and using a new domain name, and some require that you use their domain name. For instance, suppose that your name is Lola Designer and you want your Web site to be named LolaDesigner. Some Web hosting companies will allow your Web site to be LolaDesigner.com, but some will require that your Web site be named LolaDesigner.webhostingcompanyname.com, or webhostingcompanyname.com/ ~LolaDesigner, or something similar. In general, your Web site will look more professional if you use your own domain name.
  • Backups: Backups are copies of your Web page files and your database that are stored in case your files or database are lost or damaged. You want to be sure that the company makes regular, frequent backup copies of your application. You also want to know how long it would take for backups to be put in place to restore your Web site to working order after a problem.
  • Features: Select features based on the purpose of your Web site. Usually a hosting company bundles features together into plans — more features equal a higher cost. Some features to consider are
    • Disk space: How many MB or GB of disk space will your Web site require? Media files, such as graphics or music files, can be quite large.
    • Data transfer: Some hosting companies charge you for sending Web pages to users. If you expect to have a lot of traffic on your Web site, this cost should be a consideration.
    • E-mail addresses: Many hosting companies provide you with a number of e-mail addresses for your Web site. For instance, if your Web site is LolaDesigner.com, you could allow users to send you e-mail at me@LolaDesigner.com.
    • Software: Hosting companies offer access to a variety of software for Web development. PHP and MySQL are the software that I discuss in this book. Some hosting companies might offer other databases, and some might offer other development tools such as FrontPage extensions, shopping cart software, and credit card validation.
    • Statistics: Often you can get statistics regarding your Web traffic, such as the number of users, time of access, access by Web page, and so on.
One disadvantage of hosting your site with a commercial Web hosting company is that you have no control over your development environment. The Web hosting company provides the environment that works best for it — probably setting up the environment for ease of maintenance, low cost, and minimal customer defections. Most of your environment is set by the company, and you can’t change it. You can only beg the company to change it.

The company will be reluctant to change a working setup, fearing that a change could cause problems for the company’s system or for other customers. Access to MySQL databases is controlled via a system of accounts and passwords that must be maintained manually, thus causing extra work for the hosting company. For this reason, many hosting companies either don’t offer MySQL or charge extra for it. Also, PHP has myriad options that can be set, unset, or given various values.

The hosting company decides the option settings based on its needs, which might or might not be ideal for your purposes. It’s pretty difficult to research Web hosting companies from a standing start —a search at Google.com for “Web hosting” results in almost 400 million hits.

The best way to research Web hosting companies is to ask for recommendations from people who have experience with those companies. People who have used a hosting company can warn you if the service is slow or the computers are down often. After you gather a few names of Web hosting companies from satisfied customers, you can narrow the list to the one that is best suited to your purposes and the most cost effective.

Saturday, February 9, 2008

A company Web site

When the Web site is run by the company, you don’t need to understand the installation and administration of the Web site software at all. The company is responsible for the operation of the Web site. In most cases, the Web site already exists, and your job is to add to, modify, or redesign the existing Web site. In a few cases, the company might be installing its first Web site, and your job is to design the Web site. In either case, your responsibility is to write and install the HTML files for the Web site. You are not responsible for the operation of the Web site.

You access the Web site software through the company’s IT department. The name of this department can vary in different companies, but its function is the same: It keeps the company’s computers running and up to date. If PHP or MySQL or both aren’t available on the company’s Web site, IT needs to install them and make them available to you.

PHP and MySQL have many options, but IT might not understand the best options — and might have options set in ways that aren’t well suited for your purposes. If you need PHP or MySQL options changed, you need to request that IT make the change; you won’t be able to make the change yourself. For instance, PHP must be installed with MySQL support enabled, so if PHP isn’t communicating correctly with MySQL, IT might have to reinstall PHP with MySQL support enabled. For the world to see the company’s Web pages, the HTML files must be in a specific location on the computer. The Web server that delivers the Web pages to the world expects to find the HTML files in a specific directory.

The IT department should provide you with access to the directory where the HTML files need to be installed. In most cases, you develop and test your Web pages in a test location and then transfer the completed files to their permanent home. Depending on the access that IT gives you, you might copy the files from the test location to the permanent location, or you might transfer the files via FTP (File Transfer Protocol), which is a method of copying a file from one computer to another on a network.

In some cases, for security reasons, the IT folks won’t give you access to the permanent location, preferring to install the files in their permanent location themselves.

To use the Web software tools and build your dynamic Web site, you need the following information from IT:
  • The location of Web pages: You need to know where to put the files for the Web pages. IT needs to provide you with the name and location of the directory where the files should be installed. Also, you need to know how to install the files — copy them, FTP them, or use other methods. You might need a user ID and password to install the files.
  • The default filename: When users point their browsers at a URL, a file is sent to them. The Web server is set up to send a file with a specific name when the URL points to a directory. The file that is automatically sent is the default file. Very often the default file is named index.htm or index. html, but sometimes other names are used, such as default.htm. Ask IT what you should name your default file.
  • A MySQL account: Access to MySQL databases is controlled through a system of account names and passwords. IT sets up a MySQL account for you that has the appropriate permissions and also gives you the MySQL account name and password.
  • The location of the MySQL databases: MySQL databases need not be located on the same computer as the Web site. If the MySQL databases are located on a computer other than that of the Web site, you need to know the hostname (for example, thor.companyname.com) where the databases can be found.
  • The PHP file extension: When PHP is installed, the Web server is instructed to expect PHP statements in files with specific extensions. Frequently, the extensions used are .php or .phtml, but other extensions can be used. PHP statements in files that don’t have the correct extension won’t be processed. Ask IT what extension to use for your PHP programs.
You will interact with the IT folks frequently as needs arise. For example, you might need options changed, you might need information to help you interpret an error message, or you might need to report a problem with the Web site software. So a good relationship with the IT folks will make your life much easier. Bring them tasty cookies and doughnuts often.

Finding a Place to Work

To create your dynamic Web pages, you need access to a Web site that provides your three software tools (see the preceding section). All Web sites include a Web server, but not all Web sites provide MySQL and PHP. These are the most common environments in which you can develop your Web site:
  • A Web site put up by a company on its own computer: The company — usually the company’s IT (Information Technology) department — installs and administers the Web site software. Your job, for the purposes of this book, is to program the Web site, either as an employee of the company or as a contractor.
  • A Web site hosted by a Web hosting company: The Web site is located on the Web hosting company’s computer. The Web hosting company installs and maintains the Web site software and provides space on its computer where you can install the HTML (HyperText Markup Language) files for a Web site.
  • A Web site that doesn’t yet exist: You plan to install and maintain the Web site software yourself. It could be a Web site of your own that you’re building on your own computer, or it might be a Web site that you’re installing for a client on the client’s computer. How much you need to understand about the administration and operation of the Web site software depends on the type of Web site access you have. In the next few sections, I describe these environments in more detail and explain how you gain access to PHP and MySQL.

The Required Tools

To put up your dynamic Web site, you need to have access to the following three software tools:
  • A Web server: The software that delivers your Web pages to the world
  • MySQL: The RDBMS (Relational Database Management System) that will store information for your Web database application
  • PHP: The scripting language that you’ll use to write the programs that provide the dynamic functionality for your Web site

Monday, February 4, 2008

Keeping Up with PHP and MySQL Changes

PHP and MySQL are open source software. If you’ve used only software from major software publishers — such as Microsoft, Macromedia, or Adobe — you’ll find that open source software is an entirely different species. It’s developed by a group of programmers who write the code in their spare time, for fun and for free. There’s no corporate office.

Open source software changes frequently, rather than once every year or two like commercial software does. It changes when the developers feel that it’s ready. It also changes quickly in response to problems. When a serious problem is found — such as a security hole — a new version that fixes the problem can be released in days. You don’t receive glossy brochures or see splashy magazine ads for a year before a new version is released. Thus, if you don’t make the effort to stay informed, you could miss the release of a new version or be unaware of a serious problem with your current version. Visit the PHP and MySQL Web sites often.

You need to know the information that’s published there. Join the mailing lists, which often are high in traffic. When you first get acquainted with PHP and MySQL, the large number of mail messages on the discussion lists brings valuable information into your e-mail box; you can pick up a lot by reading those messages. And soon, you might be able to help others based on your own experience. At the very least, subscribe to the announcement mailing list, which delivers e-mail only occasionally. Any important problems or new versions are announced here.

The e-mail that you receive from the announcement list contains information you need to know. So, right now, before you forget, hop over to the PHP and MySQL Web sites and sign up for a list or two at www.php.net/mailing-lists. php and lists.mysql.com.
You should be aware of some significant changes in previous PHP versions because existing scripts that work fine on earlier versions could have problems when they’re run on a later version and vice versa.

How MySQL and PHP work together

PHP provides the application part, and MySQL provides the database part of a Web database application. You use the PHP language to write the programs that perform the application tasks. PHP can be used for simple tasks (such as displaying a Web page) or for complicated tasks (such as accepting and verifying data that a user typed into an HTML form). One of the tasks that your application must do is move data into and out of the database — and PHP has built-in features to use when writing programs that move data into and out of a MySQL database.

PHP statements are embedded in your HTML files with PHP tags. When the task to be performed by the application requires storing or retrieving data, you use specific PHP statements designed to interact with a MySQL database. You use one PHP statement to connect to the correct database, telling PHP where the database is located, its name, and the password needed to connect to it. The database doesn’t need to be on the same machine as your Web site;

PHP can communicate with a database across a network. You use another PHP statement to send an SQL message to MySQL, giving MySQL instructions for the task you want to accomplish. MySQL returns a status message that shows whether it successfully performed the task. If there was a problem, it returns an error message. If your SQL message asked to retrieve some data, MySQL sends the data that you asked for, and PHP stores it in a temporary location where it is available to you.

You then use one or more PHP statements to complete the application task.
For instance, you can use PHP statements to display data that you retrieved. Or you might use PHP statements to display a status message in the browser, informing the user that the data was saved.

As an RDBMS, MySQL can store complex information. As a scripting language, PHP can perform complicated manipulations of data, on either data that you need to modify before saving it in the database or data that you retrieved from the database and need to modify before displaying or using it for another task. Together, PHP and MySQL can be used to build a sophisticated and complicated Web database application.

Advantages of the relationship

MySQL and PHP as a pair have several advantages:
  • They’re free. It’s hard to beat free for cost-effectiveness.
  • They’re Web oriented. Both were designed specifically for use on Web sites. Both have a set of features focused on building dynamic Web sites.
  • They’re easy to use. Both were designed to get a Web site up quickly.
  • They’re fast. Both were designed with speed as a major goal. Together they provide one of the fastest ways to deliver dynamic Web pages to users.
  • They communicate well with one another. PHP has built-in features for communicating with MySQL. You don’t need to know the technical details; just leave it to PHP.
  • A wide base of support is available for both. Both have large user bases. Because they are often used as a pair, they often have the same user base. Many people are available to help, including those on e-mail discussion lists who have experience using MySQL and PHP together.
  • They’re customizable. Both are open source, thus allowing programmers to modify the PHP and MySQL software to fit their own specific environments.
 
breast-cancer diabetes-informa... weight-losse lung-mesotheliom... eating-disorders medical-billing php-and-mysql skin-cancer medical-health astronomy-guide cancer-diseases health insurance seo-news-2008 forex3003 lawyer-lookingforalawyer earnmoneyonline-earn forexautotrading-forex forex-trade forextrading forex-trading-forex-trading-08 searchingforcancertreatment adsense jiankang8008 beauty-girl forex5005