(Tips) Tips for Building Web Database Applications with PHP and MySQL
Tips : Tips for Building Web Database Applications with PHP and MySQL
The most popular platform for developing Web database applications is the open source trio of PHP, MySQL, and the Apache Web server. According to SecuritySpace and Netcraft, the Apache Web server is used at about 60 percent of Web sites; almost half of these servers have support for the PHP scripting language.
PHP's popularity stems from its power and flexibility: it is easy to include PHP scripts in HTML documents; it has a powerful performance-oriented library for accessing MySQL; and it shares syntax with other popular programming languages.
As a backend database management system, MySQL is the perfect partner for PHP. It has a well-deserved reputation for speed in the Web environment, where the commonest class of queries are simple SELECT queries that read from a database.
In this article, I discuss a few tips and frequently asked questions about developing with PHP and MySQL. For more information, get your hands on a copy of Web Database Applications with PHP and MySQL, which I co-authored with David Lane.
1. How to use arrays in PHP.
PHP has numerically- and associatively-indexed arrays. When you're working with databases, the associative array is your friend. I'll show you why later in my third tip, but for now let's chat about arrays and how to use them.
You're probably familiar with the numerically-indexed array. Here's an example of how to create one and print out each element:
<?php
$temp[0] = "richmond";
$temp[1] = "tigers";
$temp[2] = "premiers";
// Outputs: richmond tigers premiers
for($x=0;$x<count($temp);$x++)
{
echo $temp[$x];
echo " ";
}
?>
PHP has an elegant way to compact our example:
<?php
$temp = array("richmond", "tigers", "premiers");
// Outputs: richmond tigers premiers
foreach ($temp as $element)
echo "$element ";
?>
Courtesy:- onlamp.com
- guru's blog
- Login to post comments
