在Visual Studio中将MySQL与C ++/C#连接 [英] Connecting MySQL with C++/ C# in Visual Studio

查看:62
本文介绍了在Visual Studio中将MySQL与C ++/C#连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道C ++和(带有PHP的MySQL).但是现在我需要将MySQL与C ++连接.我需要有关MySQL服务器,MySQL连接器设置和Code :: Blocks以及连接代码的配置的帮助.请帮我.我只知道Code :: blocks或Visual Studio.关于C ++连接我不知道的有关MySQL服务器和连接器连接器的任何信息.请帮助我.

I know C++ and (MySQL with PHP). But now I need to connect MySQL with C++. I need help for MySQL server , MySQL Connector settings and configuration of Code::Blocks as well as connection code. Please help me. I know only Code::blocks or Visual Studio only. Any thing about MySQL server and Connector connector I don't know for C++ connection. Please help me.

推荐答案

对于Visual Studio 2010,请设置以下内容:

For Visual Studio 2010 setup the following :

  • MySQL服务器5.5.38(mysql-5.5.38-win32.msi)
  • MySQL Connector Net 6.8.3(mysql-connector-net-6.8.3.msi)

在Visual Studio中= >>文件= >>新建= >>项目= >> Visual C ++ = >> CLR = >> CLR空项目

In Visual Studio =>> File =>> New =>> Project =>> Visual C++ =>> CLR =>> CLR Empty Project

打开项目后,查看= >>解决方案资源管理器= >>在项目名称上,右键单击= >>属性= >> C/C ++或配置属性= >>常规= >>其他包含目录= >>单击以编辑和编写:

After opening the project, View =>> Solution Explorer =>> On Project Name Right Click =>> Properties =>> C/C++ Or Configuration Properties =>> General =>> Additional Include Directories =>> Click to edit and write:

C:\ Program Files \ MySQL \ include(或安装MySQL的目录并提及其include文件夹).

C:\Program Files\MySQL\include (or that directory where you had installed MySQL and Mention its include folder).

例如(C:\ Program Files \ MySQL \ MySQL Server 5.5 \ include)

E.g. ( C:\Program Files\MySQL\MySQL Server 5.5\include )

现在在同一属性对话框中,导航到链接器= >>常规= >>添加其他库目录" = >>(写出包含.dll或.lib文件的文件夹的路径,例如C:\ Program Files \ MySQL \连接器ODBC)

Now in same properties dialog navigate to Linker =>> General =>> "Add additional Library Directories" =>> (write the path of folder which contains .dll or .lib files e.g. C:\Program Files\MySQL\Connector ODBC)

例如(C:\ Program Files \ MySQL \ MySQL Connector Net 6.3.0)

E.g. ( C:\Program Files\MySQL\MySQL Connector Net 6.3.0 )

在同一属性对话框中,导航到链接器= >>输入= >>其他依赖关系= >>(写出您要使用的.lib文件的名称,例如libmysql.lib或要放置在其中的任何其他要使用的库以上其他图书馆目录").例如.(libmysql.lib)

In same properties dialog navigate to Linker =>> Input =>> Additional Dependencies =>> (write the name of .lib file you want to use e.g. libmysql.lib or any other library you want to use which is placed in above "Additional Library Directories"). E.g. ( libmysql.lib )

最后,如果它不起作用,请转到C:\ Program Files \ MySQL \ include(或安装MySQL的目录并提及其include文件夹).

And at last if it not work then please go to C:\Program Files\MySQL\include (or that directory where you had installed MySQL and Mention its include folder).

然后在Windows Search选项中搜索"libmysql.lib".然后将此lib文件复制到您的项目bin debug,release文件夹中.有时也可能会在错误消息中说出某些其他lib或DLL文件的要求.

Then in Windows Search option search write "libmysql.lib". Then copy this lib file in your project bin debug,release folder. Also some times it may say in error message for requirements of some other lib or DLL file.

在MySQL目录中执行相同的过程搜索,然后将其复制粘贴.如果这不起作用,则将上述DLL,lib文件复制到项目的每个文件夹中,然后在其中必须起作用.我是这样做的.

Do same process search in MySQL directory and copy-paste them. If this not work then copy the above mentioned DLL, lib file in each folder of your project then in it must work. I did in this way.

用于数据库中连接的MySQL代码:

MySQL code for connection in Database:

#include "my_global.h"
#include "mysql.h" 
#include<time.h>
#include<stdio.h>
#define SERVER "localhost"
#define USER "root"
#define PASSWORD ""
#define DATABASE "database" 
int main()
{
    char ch;
    clock_t begin, end;
    //MYSQL *connect=mysql_init(NULL); 
    //connect=mysql_real_connect(connect,SERVER,USER,PASSWORD,DATABASE,0,NULL,0); 
    //if( ! connect) { printf("MySQL Initialization or Connection Failed!\n"); return 0; }
    //mysql_query(connect,"insert into test values(2)");

    //mysql_query(connect,"INSERT INTO student VALUES('111','aaaa','bbbb')");
    begin = clock();
    //printf("Application SN\tMerit\tAdmission Roll\n-------------- ------- ----------------\n");
    MYSQL_RES *res_set; MYSQL_ROW row; 
    mysql_query(connect,"SELECT * FROM database");
    res_set = mysql_store_result(connect);  //unsigned int numrows = mysql_num_rows(res_set);   
   // while ( row = mysql_fetch_row(res_set) )
       //printf("  res  %s\t",row[0]); /* Print the row data */ 
    end = clock();
    printf("Execution Time: %f seconds\n", (double)(end - begin) / CLOCKS_PER_SEC);
    mysql_close(connect);  
    scanf("%c",&ch);
    //getch();
    //cin>>ch;
    return 0;
}

这篇关于在Visual Studio中将MySQL与C ++/C#连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆