The best language for dynamic content and database interaction

Source: Internet
Author: User
Tags what php
Article title: the best language for dynamic content and database interaction. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
If you are engaged in Web-based development, you may have heard of PHP. You may not know exactly what PHP is, how it works, or why it is so popular, but it is time to learn more about PHP. This article briefly introduces the basic concepts of PHP.
   Background knowledge
PHP is a small open source code. as more and more people become aware of its practicality, it gradually develops. Rasmus Lerdorf released the first PHP version in 1994. Since then, it has developed rapidly and has been improved and improved to version 4.0.3 through numerous improvements.
PHP is a scripting language embedded in HTML and interpreted by the server. It can be used to manage dynamic content, support databases, process session tracking, and even build the entire e-commerce site. It supports many popular databases, including MySQL, PostgreSQL, Oracle, Sybase, Informix, and Microsoft SQL Server.
   Dynamic and static content
Why is dynamic content so popular? Assume that you are managing e-commerce sites with 10 products. As long as the product does not change frequently or is not expected to change much, it is not difficult to manually compile 10 static product pages with necessary information, forms, and such content. However, assume that you want to add 10 more products this month, and then add more products next month. The price may change sometimes or you want to change the site View. Then you will be in the predicament of manually writing dozens of pages, maybe hundreds of static pages.
On the other hand, assume that you start from creating the product. php page. It does not have static information. Instead, it can be encoded to extract information from the product database and dynamically build a page. Then you have a metadata page that provides one, one hundred, or even 100,000 separate pages based on the information stored in the database. Now, the website administrator no longer simply updates static pages all day, because the website administrator can update the information on the page while updating the information in the company database. This eliminates the headache of time delay (the interval between changing information in the database and displaying information on the website ).
In general, PHP is very suitable for Web work. But it is not the only method; for example, Perl, Java, JavaScript, ASP, Python, Tcl, CGI, and many other methods can generate dynamic content. However, PHP has the following advantages: it is designed for Web-based problems and is open source code.
If you are looking for programming languages for text processing or 3D games, PHP may not be the language you need. If you need to run a website with dynamic content, database interaction, and e-commerce, continue reading, because PHP is indeed very useful in this regard.
   Applicable PHP platform
Most common PHP installation is usually a PHP module running with Linux or various UNIX Apache. But don't worry if you are using another platform. PHP can run on Windows NT, 9x, and many other Web servers. You can find more documents about PHP on some websites that mainly introduce Apache, Linux, and PHP combinations, but it is not the only platform that supports PHP.
   License and use
How much does it cost to purchase an embedded Web scripting language with all functions? Don't spend a penny? PHP is an open source project, so there is no license fee or restrictions on use. You can use PHP to run small, non-profit websites, or a billion-dollar e-commerce website at the same cost: zero. If you want to modify PHP, you can modify it.
PHP does not get the GPL license, but its own license allows redistribution of code and/or binary files.
   Use PHP
Now you are sure you want to try PHP. Let's take a look at some simple examples to give you a rough idea of PHP. Remember, this is not a way to gain an in-depth understanding of PHP, but just a quick start.
   "Hello, World! "
To understand PHP, let's take a look at several very simple PHP scripts. Since "Hello, World! "Is a common example. let's write a friendly little" Hello, World! "Script.
As mentioned earlier, PHP is embedded in HTML. (Maybe your file barely contains HTML, but this file is usually a mixture of PHP and HTML .) This means that in your normal HTML (or XHTML, if you are at the forefront), there will be PHP statements like this:
   How to say "Hello, World! "

Simple, huh?
It's easy, isn't it? This is just an "echo" statement. Of course, this alone is of little use. But it does tell us something about language. (By the way, if you check the HTML output, you will notice that the PHP code does not appear in the file sent from the slave server to your Web browser. All PHP appearing on the Web page will be processed and stripped from the page; only pure HTML output is returned from the WEB server to the client .)
Print the date and time on the Web page
Now let's do something practical. This example prints the date and time on the Web page.
   An Example of PHP in Action
Echo date ("g: I A l, F j Y.");?>
// G = the hour, in 12-hour format
// I = minutes
// A = print AM or PM, depending...
// L = print the day of the week
// F = print the month
// J = print the day of the month
// Y = print the year-all four digits
This code generates the following output:
The Current Date and Time is:
11: 00 AM Friday, October 20 2000.
Note that PHP and HTML are mixed here. If you already know HTML, only the PHP code is explained here. You can find the complete PHP reference on (see references.
PHP code is to mark End. This tells the server All the content between them needs to be analyzed using the PHP command. if they are found, they need to be executed. Please note that when processing and serving your files, the customer will receive common HTML files. Those browsing your site cannot see any PHP command. unless you make a mistake, the server splits the PHP code and does not process it first.
Generally Between regular HTML tags. Note that the preceding simple script contains
This branch mark. If the HTML format cannot be used well, PHP will not be very useful.
If you want to use it with other things, or you are a forgetful person like me, you may want to comment out the code. // The character indicates that it is a comment, and the server will not process the content marked by // or send the content to the client like the comment in HTML. If There is a standard between tags When the server performs syntax analysis on it, errors may occur. Obviously, you may not comment on your code like I do with this basic function, but it is a good example.
Note that every PHP function is enclosed in parentheses and ended with a semicolon, which is similar to C or Perl. It is common to omit an ending parentheses or semicolons due to a simple printing error, so make sure to check the code. Compiling PHP in an editor like Vim or Emacs (which can highlight the display syntax) helps to eliminate such errors. It allows you to capture errors immediately.
The date function is only one of the built-in PHP functions. PHP comes with many features available for database connection, creating PDF, Shockwave, JPG, GIF, PNG and other image files, sending emails, reading and writing files, syntax analysis XML, session processing, directly talk to the browser through HTTP, and many other functions.
PHP also allows users to define their own functions. This enables PHP to provide a large number of solutions through the Web. Instead of writing everything from the very beginning. Before writing a function, make sure that you have checked the functions such as, PHP Wizard, and Freshmeat to check whether the function you are writing is ready (see references ).
Many open-source PHP solutions are available for titles, automatically updating news websites, Web-based email clients, database management, and other aspects. It is meaningless to start from scratch. Instead, you should start with the built Foundation and customize it to your own solution. If you only have a preliminary understanding of PHP and do not have any specific projects in mind, these projects are still good examples and learning materials for using PHP.
This PHP script briefly outlines PHP functions and usage. In future articles, I will introduce how to access the MySQL database to create a dynamic Web product page. Before that, please refer to the following reference documents on PHP for more information.
Related Article

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: 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.