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