简体   繁体   中英

mysql_real_connect gives segmentation fault - C++

I'm trying to build a queue processor which grabs tasks jobs from mysql and I need the mysql connector variable to be global, because I need to use it in multiple functions. Here is the code:

...

MYSQL *connect;

...

int main(int argc, char *argv[]) {
...
   connect = mysql_init(NULL);
   if (connect == NULL) { do something and end }
   mysql_real_connect(connect, "127.0.0.1", "username", "password" , "database", 0, 0, 0);
...
   return 0;
}

Whatever I try I get en error when calling the mysql_real_connect function. Please help!

Maybe the compiler is getting connect confused with another variable or function name (like socket connect ). Try a different variable name - should have produced a warning though.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM