Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <unistd.h>
- #include <thread>
- #include <mysql/mysql.h>
- const char *mysql_host = "********";
- unsigned the_mysql_port = 13306;
- const char *mysql_db = "********";
- const char *mysql_user = "********";
- const char *mysql_pass = "********";
- const char *mysql_ssl_cert = "/usr/local/etc/certs/devmysql-client.cert";
- const char *mysql_ssl_key = "/usr/local/etc/certs/devmysql-client.key";
- void thread_func()
- {
- if (mysql_thread_init()) {
- fprintf(stderr, "mysql_thread_init\n");
- abort();
- }
- MYSQL* mysql = mysql_init(NULL);
- if (mysql == NULL) {
- fprintf(stderr, "mysql_init\n");
- abort();
- }
- if (mysql_ssl_set(mysql, mysql_ssl_key, mysql_ssl_cert, NULL, NULL, NULL)) {
- fprintf(stderr, "mysql_ssl_set\n");
- abort();
- }
- if (mysql_real_connect(mysql, mysql_host, mysql_user, mysql_pass, mysql_db, the_mysql_port, NULL, 0) == NULL) {
- fprintf(stderr, "mysql_real_connect, Error: %s\n", mysql_error(mysql));
- } else {
- fprintf(stderr, "Success!\n");
- }
- sleep(1);
- mysql_close(mysql);
- mysql_thread_end();
- }
- int main()
- {
- mysql_library_init(0, NULL, NULL);
- const size_t THREAD_COUNT = 8;
- std::thread threads[THREAD_COUNT];
- for (size_t i = 0; i < THREAD_COUNT; i++) {
- threads[i] = std::thread(thread_func);
- }
- for (size_t i = 0; i < THREAD_COUNT; i++) {
- threads[i].join();
- }
- mysql_library_end();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement