Home Database Mysql Tutorial MySQL数据库接口在VC中的实际应用有哪些?

MySQL数据库接口在VC中的实际应用有哪些?

Jun 07, 2016 pm 04:11 PM
mysql Which actual application interface database

MySQL(和PHP搭配之最佳组合)数据库作为一种网络数据库性能十分出色,但其在应用软件中使用较少。本文将主要探讨MySQL数据库接口 (ODBC API和C API)在VC中的应用,并且形成一个类用以封装C API数据库接口的功能。 利用MySQL(和PHP搭配之最佳组合)自带的C AP

MySQL(和PHP搭配之最佳组合)数据库作为一种网络数据库性能十分出色,但其在应用软件中使用较少。本文将主要探讨MySQL数据库接口 ——(ODBC API和C API)在VC中的应用,并且形成一个类用以封装C API数据库接口的功能。

利用MySQL(和PHP搭配之最佳组合)自带的C API函数实现数据库功能调用

由于各个数据库之间的差异,它们所提供的数据库功能也就各有不同。这样,通过ODBC API就不可能完全拥有所有的数据库功能,因而影响了程序对数据库的控制功能,也就不能充分发挥数据库的能力。并且这种统一的接口还是以损失效能为前提的,这就使数据库操作时间延长。所以,为了解决以上问题,MySQL(和PHP搭配之最佳组合)的制造商在提供ODBC驱动程序的基础上,还提供了各种编程环境下的API,其中包括C API。这些API函数很显然能尽可能地发挥数据库的能力,并减少数据库操作的延长时间,但却使程序的通用性受到严重影响。

MySQL(和PHP搭配之最佳组合)提供了一套C API函数,它由一组函数以及一组用于函数的数据类型组成,这些函数与MySQL(和PHP搭配之最佳组合) 服务器进行通信并访问MySQL数据库接口,可以直接操控数据库,因而显著地提高了操控效能。

C API数据类型包括:MySQL(和PHP搭配之最佳组合)(数据库连接句柄)、MySQL(和PHP搭配之最佳组合)_RES(查询返回结果集)、MySQL(和PHP搭配之最佳组合)_ROW(行集)、MySQL(和PHP搭配之最佳组合)_FIELD(字段信息)、MySQL(和PHP搭配之最佳组合)_FIELD_OFFSET(字段表的偏移量)、my_ulonglong(自定义的无符号整型数)等;

C API提供的函数包括:MySQL(和PHP搭配之最佳组合)_close()、MySQL(和PHP搭配之最佳组合)_connect()、MySQL(和PHP搭配之最佳组合)_query()、MySQL(和PHP搭配之最佳组合)_store_result()、MySQL(和PHP搭配之最佳组合)_init()等,其中MySQL(和PHP搭配之最佳组合)_query()最为重要,能完成绝大部分的数据库操控。

下面将具体讨论数据库操作类CDatabase通过C API的实现以及在VC中的应用。

查看max_connections、max_connections的办法见后。

如果 threads_connected == max_connections 时,数据库系统就不能提供更多的连接数了,这时,如果程序还想新建连接线程,数据库系统就会拒绝,如果程序没做太多的错误处理,就会出现类似强坛的报错信息。

因为创建和销毁数据库的连接,都会消耗系统的资源。而且为了避免在同一时间同时打开过多的连接线程,现在编程一般都使用所谓数据库连接池技术。

但数据库连接池技术,并不能避免程序错误导致连接资源消耗殆尽。

这种情况通常发生在程序未能及时释放数据库连接资源或其他原因造成数据库连接资源不能释放,但强坛系统估计不会发生这种低级的编程错误。

该错误的简便的检查办法是,在刷新强坛页面时,不断监视threads_connected的变化。如果max_connections足够大,而threads_connected值不断增加以至达到max_connections,那么,就应该检查程序了。当然,如果采用数据库连接池技术,threads_connected增长到数据库连接池的最大连接线程数时,就不再增长了。

从强坛出错的情况看,更大的可能性是数据库系统没能进行适当地配置。下面提出一点建议。供参考

让你们的工程师把MySQL(和PHP搭配之最佳组合)的最大允许连接数从默认的100调成32000。这就不会老出现连接过多的问题了。

查看max_connections

进入MySQL(和PHP搭配之最佳组合),用命令:show variables

查看MySQL数据库接口最大可连接数的变量值:max_connections

查看threads_connected

进入MySQL(和PHP搭配之最佳组合),用命令:show status

查看当前活动的连接线程变量值:threads_connected

设置max_connections

设置办法是在my.cnf文件中,添加下面的最后红色的一行:

<ol class="dp-xml">
<li class="alt"><span><span>[MySQL(和PHP搭配之最佳组合)d]   </span></span></li>
<li>
<span class="attribute">port</span><span>=</span><span class="attribute-value">3306</span><span>   </span>
</li>
<li class="alt">
<span>#</span><span class="attribute">socket</span><span>=</span><span class="attribute-value">MySQL</span><span>(和PHP搭配之最佳组合)   </span>
</li>
<li><span>skip-locking   </span></li>
<li class="alt">
<span class="attribute">set-variable</span><span> = </span><span class="attribute-value">key_buffer</span><span>=16K   </span>
</li>
<li>
<span class="attribute">set-variable</span><span> = </span><span class="attribute-value">max_allowed_packet</span><span>=1M   </span>
</li>
<li class="alt">
<span class="attribute">set-variable</span><span> = </span><span class="attribute-value">thread_stack</span><span>=64K   </span>
</li>
<li>
<span class="attribute">set-variable</span><span> = </span><span class="attribute-value">table_cache</span><span>=4   </span>
</li>
<li class="alt">
<span class="attribute">set-variable</span><span> = </span><span class="attribute-value">sort_buffer</span><span>=64K   </span>
</li>
<li>
<span class="attribute">set-variable</span><span> = </span><span class="attribute-value">net_buffer_length</span><span>=2K   </span>
</li>
<li class="alt">
<span class="attribute">set-variable</span><span> = </span><span class="attribute-value">max_connections</span><span>=32000  </span>
</li>
</ol>
Copy after login

修改完毕后,重启MySQL(和PHP搭配之最佳组合)即可。当然,为了确保设置正确,应该查看一下max_connections。

注意:

1、虽然这里写的32000。但实际MySQL(和PHP搭配之最佳组合)服务器允许的最大连接数16384;

2、除max_connections外,上述其他配置应该根据你们系统自身需要进行配置,不必拘泥;

3、添加了最大允许连接数,对系统消耗增加不大。

4、如果你的MySQL(和PHP搭配之最佳组合)用的是my.ini作配置文件,设置类似,但设置的格式要稍作变通。


Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

MySQL's Role: Databases in Web Applications MySQL's Role: Databases in Web Applications Apr 17, 2025 am 12:23 AM

The main role of MySQL in web applications is to store and manage data. 1.MySQL efficiently processes user information, product catalogs, transaction records and other data. 2. Through SQL query, developers can extract information from the database to generate dynamic content. 3.MySQL works based on the client-server model to ensure acceptable query speed.

How to start mysql by docker How to start mysql by docker Apr 15, 2025 pm 12:09 PM

The process of starting MySQL in Docker consists of the following steps: Pull the MySQL image to create and start the container, set the root user password, and map the port verification connection Create the database and the user grants all permissions to the database

Laravel Introduction Example Laravel Introduction Example Apr 18, 2025 pm 12:45 PM

Laravel is a PHP framework for easy building of web applications. It provides a range of powerful features including: Installation: Install the Laravel CLI globally with Composer and create applications in the project directory. Routing: Define the relationship between the URL and the handler in routes/web.php. View: Create a view in resources/views to render the application's interface. Database Integration: Provides out-of-the-box integration with databases such as MySQL and uses migration to create and modify tables. Model and Controller: The model represents the database entity and the controller processes HTTP requests.

Solve database connection problem: a practical case of using minii/db library Solve database connection problem: a practical case of using minii/db library Apr 18, 2025 am 07:09 AM

I encountered a tricky problem when developing a small application: the need to quickly integrate a lightweight database operation library. After trying multiple libraries, I found that they either have too much functionality or are not very compatible. Eventually, I found minii/db, a simplified version based on Yii2 that solved my problem perfectly.

Oracle's Role in the Business World Oracle's Role in the Business World Apr 23, 2025 am 12:01 AM

Oracle is not only a database company, but also a leader in cloud computing and ERP systems. 1. Oracle provides comprehensive solutions from database to cloud services and ERP systems. 2. OracleCloud challenges AWS and Azure, providing IaaS, PaaS and SaaS services. 3. Oracle's ERP systems such as E-BusinessSuite and FusionApplications help enterprises optimize operations.

Laravel framework installation method Laravel framework installation method Apr 18, 2025 pm 12:54 PM

Article summary: This article provides detailed step-by-step instructions to guide readers on how to easily install the Laravel framework. Laravel is a powerful PHP framework that speeds up the development process of web applications. This tutorial covers the installation process from system requirements to configuring databases and setting up routing. By following these steps, readers can quickly and efficiently lay a solid foundation for their Laravel project.

MySQL and phpMyAdmin: Core Features and Functions MySQL and phpMyAdmin: Core Features and Functions Apr 22, 2025 am 12:12 AM

MySQL and phpMyAdmin are powerful database management tools. 1) MySQL is used to create databases and tables, and to execute DML and SQL queries. 2) phpMyAdmin provides an intuitive interface for database management, table structure management, data operations and user permission management.

MySQL vs. Other Programming Languages: A Comparison MySQL vs. Other Programming Languages: A Comparison Apr 19, 2025 am 12:22 AM

Compared with other programming languages, MySQL is mainly used to store and manage data, while other languages ​​such as Python, Java, and C are used for logical processing and application development. MySQL is known for its high performance, scalability and cross-platform support, suitable for data management needs, while other languages ​​have advantages in their respective fields such as data analytics, enterprise applications, and system programming.

See all articles