Home Database Mysql Tutorial vs2010 c++ 链接mysql

vs2010 c++ 链接mysql

Jun 07, 2016 pm 03:25 PM
c++ mysql vs2010 Establish connect Link

第一步 建立连接前的配置 来源是mysql的官网配置文件 :http://dev.mysql.com/doc/refman/5.6/en/connector-cpp-apps-windows-visual-studio.html (1)在c项目-属性- 配置属性-c/c-常规-附加包含目录 包括进 C:\Program Files\MySQL\MySQL Server 5.5\inclu

第一步 建立连接前的配置

来源是mysql的官网配置文件 :http://dev.mysql.com/doc/refman/5.6/en/connector-cpp-apps-windows-visual-studio.html

(1)在c++项目->属性-> 配置属性->c/c++->常规->附加包含目录  包括进   C:\Program Files\MySQL\MySQL Server 5.5\include 

(2)在c++项目->属性-> 配置属性->链接器->常规->附加库目录   包括进   C:\Program Files\MySQL\MySQL Server 5.5\lib   C:\Program Files\MySQL\MySQL Connector C++ 1.1.3\lib\opt

(3)在c++项目->属性-> 配置属性->链接器->输入->附加依赖项    加入 libmysql.lib  mysqlcppconn-static.lib

   配置基本完成,说明一下,在上边的配置中我的机子上安装了vs2010,mysq5.5,Connector C++ 1.1.3。

第二步  数据库连接操作代码

#include "stdafx.h"

#include<winsock2.h>
//定义socket
#include<iostream>

#include <mysql.h>
//#pragma comment( lib, "libmysql.lib");
//此句话和在附加依赖项中增加libmysql.lib 的功能一样


using namespace std;
int main(char **args)
{
	MYSQL mysql;
	mysql_init(&mysql);
	if (mysql_real_connect(&mysql,"localhost","root","123","test",3306,0,0))
	{
		cout第三步 常用的myql  api
<p>API 以及他们呢的解释 :http://dev.mysql.com/doc/refman/5.1/zh/apis.html</p>
<p>附MySQL的API接口<br>
mysql_affected_rows() 返回被最新的UPDATE, DELETE或INSERT查询影响的行数。<br>
mysql_close() 关闭一个服务器连接。<br>
mysql_connect() 连接一个MySQL服务器。该函数不推荐;使用mysql_real_connect()代替。<br>
mysql_change_user() 改变在一个打开的连接上的用户和数据库。<br>
mysql_create_db() 创建一个数据库。该函数不推荐;而使用SQL命令CREATE DATABASE。<br>
mysql_data_seek() 在一个查询结果集合中搜寻一任意行。<br>
mysql_debug() 用给定字符串做一个DBUG_PUSH。<br>
mysql_drop_db() 抛弃一个数据库。该函数不推荐;而使用SQL命令DROP DATABASE。<br>
mysql_dump_debug_info() 让服务器将调试信息写入日志文件。<br>
mysql_eof() 确定是否已经读到一个结果集合的最后一行。这功能被反对; mysql_errno()或mysql_error()可以相反被使用。<br>
mysql_errno() 返回最近被调用的MySQL函数的出错编号。<br>
mysql_error() 返回最近被调用的MySQL函数的出错消息。<br>
mysql_escape_string() 用在SQL语句中的字符串的转义特殊字符。<br>
mysql_fetch_field() 返回下一个表字段的类型。<br>
mysql_fetch_field_direct () 返回一个表字段的类型,给出一个字段编号。<br>
mysql_fetch_fields() 返回一个所有字段结构的数组。<br>
mysql_fetch_lengths() 返回当前行中所有列的长度。<br>
mysql_fetch_row() 从结果集合中取得下一行。<br>
mysql_field_seek() 把列光标放在一个指定的列上。<br>
mysql_field_count() 返回最近查询的结果列的数量。<br>
mysql_field_tell() 返回用于最后一个mysql_fetch_field()的字段光标的位置。<br>
mysql_free_result() 释放一个结果集合使用的内存。<br>
mysql_get_client_info() 返回客户版本信息。<br>
mysql_get_host_info() 返回一个描述连接的字符串。<br>
mysql_get_proto_info() 返回连接使用的协议版本。<br>
mysql_get_server_info() 返回服务器版本号。<br>
mysql_info() 返回关于最近执行得查询的信息。<br>
mysql_init() 获得或初始化一个MYSQL结构。<br>
mysql_insert_id() 返回有前一个查询为一个AUTO_INCREMENT列生成的ID。<br>
mysql_kill() 杀死一个给定的线程。<br>
mysql_list_dbs() 返回匹配一个简单的正则表达式的数据库名。<br>
mysql_list_fields() 返回匹配一个简单的正则表达式的列名。<br>
mysql_list_processes() 返回当前服务器线程的一张表。<br>
mysql_list_tables() 返回匹配一个简单的正则表达式的表名。<br>
mysql_num_fields() 返回一个结果集合重的列的数量。<br>
mysql_num_rows() 返回一个结果集合中的行的数量。<br>
mysql_options() 设置对mysql_connect()的连接选项。<br>
mysql_ping() 检查对服务器的连接是否正在工作,必要时重新连接。<br>
mysql_query() 执行指定为一个空结尾的字符串的SQL查询。<br>
mysql_real_connect() 连接一个MySQL服务器。<br>
mysql_real_query() 执行指定为带计数的字符串的SQL查询。<br>
mysql_reload() 告诉服务器重装授权表。<br>
mysql_row_seek() 搜索在结果集合中的行,使用从mysql_row_tell()返回的值。<br>
mysql_row_tell() 返回行光标位置。<br>
mysql_select_db() 连接一个数据库。<br>
mysql_shutdown() 关掉数据库服务器。<br>
mysql_stat() 返回作为字符串的服务器状态。<br>
mysql_store_result() 检索一个完整的结果集合给客户。<br>
mysql_thread_id() 返回当前线程的ID。<br>
mysql_use_result() 初始化一个一行一行地结果集合的检索。<br>
<br>
</p>


</mysql.h></iostream></winsock2.h>
Copy after login
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)

Centos install mysql Centos install mysql Apr 14, 2025 pm 08:09 PM

Installing MySQL on CentOS involves the following steps: Adding the appropriate MySQL yum source. Execute the yum install mysql-server command to install the MySQL server. Use the mysql_secure_installation command to make security settings, such as setting the root user password. Customize the MySQL configuration file as needed. Tune MySQL parameters and optimize databases for performance.

The Performance Race: Golang vs. C The Performance Race: Golang vs. C Apr 16, 2025 am 12:07 AM

Golang and C each have their own advantages in performance competitions: 1) Golang is suitable for high concurrency and rapid development, and 2) C provides higher performance and fine-grained control. The selection should be based on project requirements and team technology stack.

How to install mysql in centos7 How to install mysql in centos7 Apr 14, 2025 pm 08:30 PM

The key to installing MySQL elegantly is to add the official MySQL repository. The specific steps are as follows: Download the MySQL official GPG key to prevent phishing attacks. Add MySQL repository file: rpm -Uvh https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm Update yum repository cache: yum update installation MySQL: yum install mysql-server startup MySQL service: systemctl start mysqld set up booting

Golang vs. C  : Code Examples and Performance Analysis Golang vs. C : Code Examples and Performance Analysis Apr 15, 2025 am 12:03 AM

Golang is suitable for rapid development and concurrent programming, while C is more suitable for projects that require extreme performance and underlying control. 1) Golang's concurrency model simplifies concurrency programming through goroutine and channel. 2) C's template programming provides generic code and performance optimization. 3) Golang's garbage collection is convenient but may affect performance. C's memory management is complex but the control is fine.

How to run programs in terminal vscode How to run programs in terminal vscode Apr 15, 2025 pm 06:42 PM

In VS Code, you can run the program in the terminal through the following steps: Prepare the code and open the integrated terminal to ensure that the code directory is consistent with the terminal working directory. Select the run command according to the programming language (such as Python's python your_file_name.py) to check whether it runs successfully and resolve errors. Use the debugger to improve debugging efficiency.

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

Do you use c in visual studio code Do you use c in visual studio code Apr 15, 2025 pm 08:03 PM

Writing C in VS Code is not only feasible, but also efficient and elegant. The key is to install the excellent C/C extension, which provides functions such as code completion, syntax highlighting, and debugging. VS Code's debugging capabilities help you quickly locate bugs, while printf output is an old-fashioned but effective debugging method. In addition, when dynamic memory allocation, the return value should be checked and memory freed to prevent memory leaks, and debugging these issues is convenient in VS Code. Although VS Code cannot directly help with performance optimization, it provides a good development environment for easy analysis of code performance. Good programming habits, readability and maintainability are also crucial. Anyway, VS Code is

How to choose a GitLab database in CentOS How to choose a GitLab database in CentOS Apr 14, 2025 pm 05:39 PM

When installing and configuring GitLab on a CentOS system, the choice of database is crucial. GitLab is compatible with multiple databases, but PostgreSQL and MySQL (or MariaDB) are most commonly used. This article analyzes database selection factors and provides detailed installation and configuration steps. Database Selection Guide When choosing a database, you need to consider the following factors: PostgreSQL: GitLab's default database is powerful, has high scalability, supports complex queries and transaction processing, and is suitable for large application scenarios. MySQL/MariaDB: a popular relational database widely used in Web applications, with stable and reliable performance. MongoDB:NoSQL database, specializes in

See all articles