PHP and MySQL (1)

Source: Internet
Author: User
Tags php introduction
PHP and MySQL (1) in this chapter, we will introduce the script language on the PHP server. We will see that this language supports communication with the MySQL database.

PHP introduction

As we mentioned earlier, PHP is a server-side scripting language. This concept may be hard to understand, especially if you have used HTML and JavaScript to design web pages before. A server-side scripting program is similar to JavaScript in many places, both of which allow you to insert some programs (scripts) in the HTML on the web page ). The result is that these scripts allow you to control what will be displayed in the browser window, which is obviously more flexible than using HTML directly.

The key difference between JavaScript and PHP is that when a Web browser interprets JavaScript, the Web page containing the script has been downloaded. for server-side scripting programs such as PHP, the work explained is completely done by the server before the page is sent to the browser. After the explanation is complete, the PHP code on the Web page will be replaced by the script running result, and the viewer will see a standard HTML file. Scripts are completely processed by the server. This is the origin of its naming: server-side scripting.

Let's look back at the example today. php we created in Chapter 1:



Today's Date


Today's Date (according to this Web server) is
Echo (date ("l, F dS Y ."));
?>

Most of this program uses HTML format. Only The middle line is written in PHP. End PHP code ". Before sending the Web page to the browser requesting it, the Web server processes all the content before the two identifiers and converts them into standard HTML code. The page received by the browser will be as follows:



Today's Date


Today's Date (according to this Web server) is
Wednesday, June 7th 2000.

Note that all PHP code is not displayed. They are replaced by the corresponding standard HTML. through this example, we can see several advantages of server-side scripts:

There is no browser compatibility problem. PHP scripts are only explained by Web servers, so we don't have to worry about whether your language can be supported by your visitor's browser.

You can access resources on the server. In the preceding example, we place the date of the Web server on the Web page. When we use JavaScript, to implement the same function, we can only display the date of the computer on which the Web browser runs. This example is not very typical for using server resources. In fact, we can easily insert some other information, which can only be called by running scripts on the server, for example, the information stored in the MySQL database running on the Web server.

Simplifies client loading. JavaScript significantly reduces the display speed of Web pages, because before displaying this Web page, the browser must first run JavaScript scripts. For Server Scripts, the Web server alone bears this burden.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.