Doing PHP queries to a MySQL database is one of the most important processes in any web application. This is where data is being fetched from or inserted into the database. If you are a beginning PHP web developer, then learning the most important MySQL queries is essential to your success in dealing with dynamic websites.
You can see dynamic websites almost everywhere on the net. Popular software packages, whether for blogging (like WordPress or Drupal) or e-commerce (such as osCommerce) are configured to be dynamic in nature. Dynamic websites rely on MySQL databases to fetch and insert data coming from and going to the browser.
If you are beginner, understanding the simple diagram below helps you to understand the role of MySQL in today's dynamic websites as compared to the traditional static websites.
In a simple static websites (popular in the old days of the Internet), you would see the following flow of events:
Client browser request for information from the server -> Server returns HTML code to the browser -> Browser displays the HTML, which becomes a web page.
Now, in modern dynamic websites:
The client browser requests a web page, and when the server receives the request, the web template (those files with the extension *.php) executes the PHP scripts that involve fetching information (involving queries) from MySQL (such as your name, password, content, or anything else). The information will then be added to the web template, and then return to the browser as HTML. When you view the source code, you cannot see the PHP scripts any longer, because they have already been executed in the server.
With dynamic websites, you can create a thousand URLs with only one server PHP template stored. But with static websites, you need to store 1000 HTML files in your server to create 1000 URLs (which is very difficult to manage or update). Do you see the difference?
If you know the most important MySQL queries, it will then be very easy to communicate with the database, thus enabling you to create complex PHP web applications. This will save you time and make your website as efficient as possible. In this tutorial, we will illustrate PHP scripts that will query a MySQL database using the basic INSERT, SELECT, and UPDATE commands.