MySQL database technology (28) _ MySQL

Source: Internet
Author: User
MySQL database technology (28) 5.2 Select API

This section describes how to select a p I based on various types of applications, compares the capabilities of C, DBI, and PHP APIs, and provides their advantages and disadvantages, and specify the time when to select.

First, we should point out that I do not think any language is better than other languages. Although I do have my own preferences, I still use them all. You will also have your own preferences, like my critics. One critic will feel that the importance of C for MySQL programming should be emphasized, and the importance should be raised to a more important level. the other reviewer will think that C programming is quite difficult and should give up using it! You should weigh the factors discussed in this section and draw your own conclusions. When selecting an API for a specific task, consider the following:

■ Expected execution environment. The context of the application.

■ Performance. How to make the application run efficiently when writing in the API language.

■ Ease of development. How to easily write applications using APIs and their language.

■ Portability. In addition to MySQL, Will applications be used in other database systems.

Next we will further analyze each problem. Pay attention to the mutual influence of these factors. For example, if you want an application that runs well, it is equally important to use a language that allows you to quickly develop the application, even if the application cannot run very effectively.

5.2.1 execution environment

Which environment should be considered when writing an application. For example, the application may be a report generator program called from the shell, or an account payable Summary program that runs as a cron job at the end of each month. Commands run from Shell programs or cron programs usually depend on themselves and seldom need to run the environment. In addition, you can write an application to try to be called by the Web server. Such a program is expected to extract a very special type of information from its running environment: what browser is the customer using? What parameters are input in the mail list subscription request format? Does the customer provide the correct password to access our personal information? Each API language changes with its suitability for compiling applications in these different environments:

■ C is a common target language. Theoretically, any task can be used. In reality, C tends to be used for more frequent independent programs rather than Web programming. The possible cause is that in C, text processing and memory management are not as easy as in Perl or PHP, and these processing and management are largely used in Web applications.

■ P e r l, like C, is suitable for writing independent programs. However, Perl is also very useful for Web site development, for example by using the CGI. pm module. This makes Perl a convenient language for compiling applications connected to MySQL and the Web. Such applications can use CGI. pm modules and Web interfaces, and use DBI to interact with MySQL.

■ PHP is the language designed to write Web applications, so this environment is obviously the most suitable. In addition, database access is one of the biggest advantages of PHP, so it is the most natural choice for Web applications that implement MySQL-related tasks. PHP can also be used as an independent interpreter (for example, running a script from the shell), but it cannot be used very frequently.

Based on the above issues, C and Perl are the best languages for independent applications. For the We B application, Perl and PHP are the most suitable. If you need to write these two types of applications without using any of these languages and want to learn with as little effort as possible, Perl may be your best choice.

5.2.2 performance

We usually like to run applications as fast as possible. However, the importance of performance depends on the frequency of the program used. Performance may not be very important for a program that runs regular jobs at night once a month. For programs that run several times on a Web site in a second, it will bring a huge difference whenever any invalidity is ruled out. In the latter case, performance plays an important role in site validity and requests. A slow website is a headache for users. regardless of the content of the site, if you rely on the site as a source of revenue, the reduction of performance will directly affect your income. If you cannot provide services for multiple connections at a time, visitors will get bored and go to other sites.

Performance Evaluation is a complex problem. When writing a specific API, the best indicator for the application to do well is to write and test it in this API environment. In addition, the best comparative test is to run the application multiple times in different API environments to compare each version. Of course, it is not a normal job. Generally, you only want to obtain the compiled application. Once it works, if it needs to run faster, you can consider optimizing it, using less memory, or some aspects that need to be improved in other ways. However, there are at least two factors that affect performance:

■ Compiled programs run faster than interpreted programs.

■ The interpreted language used in the Web context provides better performance when the interpreter is called as a part of the We B server rather than a separate process module.

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.