Guest User

Untitled

a guest
Sep 5th, 2017
145
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <mysql/mysql.h>
  2. #include <stdio.h>
  3.  
  4. const char *sock = "/tmp/akonadi-babydragon.9F3Ue5/mysql.socket";
  5.  
  6. void connectOnce() {
  7.         if(mysql_library_init(0, 0, 0)) {
  8.                 printf("lib init fail\n");
  9.         }
  10.  
  11.         MYSQL *mysql = mysql_init(NULL);
  12.         if(mysql_real_connect(mysql, NULL, NULL, NULL, NULL, 0, sock, 0) == NULL) {
  13.                 printf("connect fail: %s\n", mysql_error(mysql));
  14.         }
  15.  
  16.         mysql_close(mysql);
  17.  
  18.         mysql_library_end();
  19. }
  20.  
  21. int main() {
  22.         printf("first connect\n");
  23.         connectOnce();
  24.         printf("second connect\n");
  25.         connectOnce();
  26.         return 0;
  27. }
RAW Paste Data