What are the practical applications of MySQL database interfaces in VC?

Source: Internet
Author: User
Tags field table

As a network database, MySQL (the best combination with PHP) has excellent performance, but it is rarely used in application software. This article will mainly discuss the application of MySQL database interface-odbc api and c api) in VC, and form a class to encapsulate the function of c api database interface.

Use the c api functions provided by MySQL (the best combination with PHP) to call database functions.

Because of the differences between databases, the database functions they provide are also different. In this way, the odbc api cannot have all the database functions, thus affecting the Database Control Function of the program, and thus the database capabilities cannot be fully utilized. In addition, this unified interface is based on the loss of efficiency, which prolongs the database operation time. To solve the preceding problems, MySQL (the best combination with PHP) manufacturers provide ODBC drivers and APIs in various programming environments, including c api. Obviously, these API functions can exert the database capabilities as much as possible and reduce the extended time of database operations, but the universality of the program is seriously affected.

MySQL (the best combination with PHP) provides a set of c api functions, which consist of a group of functions and a group of data types used for functions, these functions communicate with the MySQL (the best combination with PHP) server and access the MySQL database interface to directly manipulate the database, thus significantly improving the control efficiency.

C api data types include: MySQL (the best combination with PHP) database connection handle), MySQL (the best combination with PHP) _ RES query return result set), MySQL (the best combination with PHP) _ ROW set), MySQL (the best combination with PHP) _ FIELD information), MySQL (the best combination with PHP) _ FIELD_OFFSET field Table offset), my_ulonglong custom unsigned integer number), and so on;

Functions provided by c api include: MySQL (the best combination with PHP) _ close (), MySQL (the best combination with PHP) _ connect (), MySQL (the best combination with PHP) _ query (), MySQL (the best combination with PHP) _ store_result (), MySQL (the best combination with PHP) _ init (), among which MySQL (the best combination with PHP) _ query () is the most important and can complete most of the database operations.

The following describes the implementation of database operation class CDatabase through c api and the Application in VC.

For more information about how to view max_connections and max_connections, see.

If threads_connected = max_connections, the database system cannot provide more connections. In this case, if the program wants to create a new connection thread, the database system will reject the connection, if the program does not handle too many errors, an error message similar to the strong altar will appear.

Because the creation and destruction of database connections consume system resources. To avoid opening too many connection threads at the same time, the so-called database connection pool technology is usually used for programming.

However, the database connection pool technology does not prevent connection resources from being exhausted due to program errors.

This usually happens when the program fails to release the database connection resources in time or other reasons cause the database connection resources to be unable to be released. However, it is estimated that this low-level programming error will not occur in the strong altar system.

The easy way to check this error is to constantly monitor the changes of threads_connected when refreshing the strong altar page. If max_connections is large enough, and the value of threads_connected is constantly increasing to reach max_connections, check the program. Of course, if you use the database connection pool technology, threads_connected will not grow to the maximum number of connection threads in the database connection pool.

From the perspective of a strong altar error, it is more likely that the database system fails to be properly configured. The following are some suggestions. For reference

Ask your engineers to change the maximum allowed connections of MySQL (the best combination with PHP) from the default 100 to 32000. This will not cause too many connections.

View max_connections

Go to MySQL (the best combination with PHP) and run the command: show variables.

The variable value for viewing the maximum number of connections of the MySQL database interface: max_connections

View threads_connected

Go to MySQL (the best combination with PHP) and run the command: show status.

Check the value of the currently active connection thread variable: threads_connected

Set max_connections

The setting method is to add the last red line below in the my. cnf file:

 
 
  1. [MySQL (the best combination with PHP) d]
  2. Port = 3306
  3. # Socket = MySQL (the best combination with PHP)
  4. Skip-locking
  5. Set-variable = key_buffer = 16 K
  6. Set-variable = max_allowed_packet = 1 M
  7. Set-variable = thread_stack = 64 K
  8. Set-variable = table_cache = 4
  9. Set-variable = sort_buffer = 64 K
  10. Set-variable = net_buffer_length = 2 K
  11. Set-variable = max_connections = 32000

After modification, restart MySQL (the best combination of PHP and MySQL. Of course, to ensure correct settings, check max_connections.

Note:

1. Although 32000 is written here. However, the actual MySQL (best combination with PHP) server allows a maximum of 16384 connections;

2. In addition to max_connections, the above configurations should be configured according to your system's own needs;

3. added the maximum number of allowed connections, which does not increase the system consumption much.

4. If your MySQL (the best combination with PHP) uses my. ini as the configuration file, the setting is similar, but the setting format must be slightly changed.

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.