mysql query 用法c,MySQL_Query使用C ++

Hi Guys,

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 *conn; // pointer to MySQL structure

conn = mysql_init(NULL); // connection handle

// Connect to MySQL database

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

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

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

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

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

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->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;

else

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

net=0xffffff;

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

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

return(2);

}

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

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

return(2);

}

It returned me an error.

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

I don't really get what is going on.

解决方案Hi LeRoyce,

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.

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值