MySQL with C++
Posted by: Royce Ho
Date: January 05, 2012 10:47PM

Hi Guys,

How do i get a value from the database and assign it to a variable using C++ language.

My program requires me to extract a value from the "setting" table, field=filter, get the value and assign it to

char filter_exp[] = ""; /* The filter expression */

The null value is actually what i query for in the "setting" table, field=filter.

Lets say for example TCP. It will actually assign TCP to that variable.

Please advice.


These are some codes from my program.

char filter_exp[] = ""; /* The filter expression */

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);
sprintf(cmd6, "DELETE FROM start");
mysql_real_query(conn, cmd6 , strlen(cmd6));


mysql_query(conn, "SELECT Filter from setting where transmit='1'");


-------------------------------------------------------------------------------

/*
* 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);
}

Options: ReplyQuote


Subject
Views
Written By
Posted
MySQL with C++
2150
January 05, 2012 10:47PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.