MySQL_Query使用C ++ [英] MySQL_Query With C++

查看:92
本文介绍了MySQL_Query使用C ++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我正在寻找如何从数据库(MySQL)中提取数据并将其分配到我的程序中的变量中。这里有一些代码可以举例说明我的意思。

I'm finding out how to extract data out from database(MySQL) and assign it into a variable in my program. Here are some codes to give an example of what i meant.

MYSQL_RES * filter_exp;

MYSQL_RES *filter_exp;

 

MYSQL * conn; //指向MySQL结构的指针

MYSQL *conn; // pointer to MySQL structure

conn = mysql_init(NULL); //连接句柄

conn = mysql_init(NULL); // connection handle

    //连接MySQL数据库

   // Connect to MySQL database

    //主机地址= localhost,用户名= root,数据库=项目

   // host address = localhost, username = root, database = project

    mysql_real_connect(conn,"localhost"," root","",""project",0,NULL,0); 

   mysql_real_connect(conn, "localhost", "root", "", "project", 0, NULL, 0); 

    MYSQL_RES * res_set; / *创建一个指针来接收返回值。*

   MYSQL_RES *res_set; /* Create a pointer to recieve the return value.*

mysql_query(conn,"SELECT Filter FROM setting"); / *向数据库发送查询。 * /

mysql_query(conn,"SELECT Filter FROM setting"); /* Send a query to the database. */

filter_exp = mysql_store_result(conn); / *收到结果并将其存储在res_set * /

filter_exp = mysql_store_result(conn); /* Receive the result and store it in res_set */

 

 

  ;

但是,它仍有错误。在我的代码的底部,有一大堆编码,其中声明了filter_exp。

But still, it has errors. At the bottom of my codes, there is this junk of codings where filter_exp is declared.

 

 

/ * 

/* 

    *编译+设置过滤器

   * Compiling + setting the filter

    *

   *

    * /

   */

 

  if(lDevice- >地址!= NULL)

 if (lDevice->addresses != NULL)

        / *检索界面第一个地址的掩码* /

        /* Retrieve the mask of the first address of the interface */

        net =((struct sockaddr_in *)(lDevice-> addresses-> netmask)) - > sin_addr.S_un.S_addr;

        net=((struct sockaddr_in *)(lDevice->addresses->netmask))->sin_addr.S_un.S_addr;

   否则

    else

        / *如果界面没有地址,我们认为是在C类网络中* /

        /* If the interface is without an address we suppose to be in a C class network */

        net = 0xffffff;

        net=0xffffff;

 

  if(pcap_compile( lIFCHandle,& lFCode,filter_exp,0,net)== -1){

 if (pcap_compile(lIFCHandle, &lFCode, filter_exp, 0, net) == -1) {

  fprintf(stderr ,"无法解析过滤器%s:%s \ n",filter_exp,pcap_geterr(lIFCHandle));

 fprintf(stderr, "Couldn't parse filter %s: %s\n", filter_exp, pcap_geterr(lIFCHandle));

  ; return(2);

 return(2);

  }

  if(pcap_setfilter(lIFCHandle,& lFCode)== -1){

 if (pcap_setfilter(lIFCHandle, &lFCode) == -1) {

  fprintf(stderr,"无法安装过滤器%s:%s \ n",filter_exp,pcap_geterr(lIFCHandle));

 fprintf(stderr, "Couldn't install filter %s: %s\n", filter_exp, pcap_geterr(lIFCHandle));

  return(2);

 return(2);

  }

 

 

它给我一个错误。

 

ARGUMENT OF TYPE" MYSQL_RES *"与"CONST CHAR *"的参数不相容

ARGUMENT OF TYPE "MYSQL_RES *" IS INCOMPATIBLE WITH PARAMETER OF TYPE "CONST CHAR * "

 

我真的不知道发生了什么。

I don't really get what is going on.

 

推荐答案

您好LeRoyce,

Hi LeRoyce,

我建议您使用以下链接,其中包含示例程序并讨论如何访问MySQL数据库。

请参阅 他们有关更多有用信息:
http://www.codeproject.com/KB/ CPP / sdba.aspx
。本文讨论如何使用Visual C ++将图像上传到MySQL数据库:

http://www.codeproject.com/KB/database/mysqlimageimport.aspx


这是另一个在Visual C ++ General论坛中处理VC ++和MySQL的线程。请参阅它以获取更多有用的信息:

http://social.msdn.microsoft.com/Forums/en-US/vcgeneral/thread/c355f043-db6d-4d36-ae87-f9a4575be4b1

I recommend the following links for you, which contain sample routines and talk about how to access MySQL data base.
Please refer to them for more helpful information: http://www.codeproject.com/KB/cpp/sdba.aspx. And this article discusses how to upload images to MySQL database using Visual C++: http://www.codeproject.com/KB/database/mysqlimageimport.aspx.
And here is another thread which deals with VC++ and MySQL in Visual C++ General forum. Please refer to it for more helpful information: http://social.msdn.microsoft.com/Forums/en-US/vcgeneral/thread/c355f043-db6d-4d36-ae87-f9a4575be4b1.

顺便说一句,MySQL不是微软的产品。如果您对MySQL有疑问,我建议您转到" MySQL论坛"。为了获得更有效的回复。

By the way, MySQL is not a product of Microsoft. If you have questions about MySQL, I suggest you move to "MySQL Forums" to get more efficient responses.

最好的问候,

海伦

Best regards,
Helen


这篇关于MySQL_Query使用C ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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