MYSQL C API : mysql_real_connect()

來源:互聯網
上載者:User

標籤:

MYSQL * mysql_real_connect(

MYSQL *mysql,
const char *host,
const char *user,
const char *passwd,
const char *db,
unsigned int port,
const char *unix_socket,
unsigned long clientflag);

// 串連到MYSQL 資料庫伺服器 在標頭檔mysql.h 中聲明
// 參數的說明請參考百度百科

代碼範例:

 1 #include <iostream> 2 #include <mysql.h> 3 #include <string> 4  5 #include <assert.h> 6  7 int main() 8 { 9     MYSQL *ms_conn = mysql_init(NULL);10     if (ms_conn == NULL)11     {12         std::cout << "Error: mysql_init failed." << std::endl;13         return 0;14     }15     std::cout << "Info: mysql_init successful." << std::endl;16 17     MYSQL *ms_res = NULL;18     ms_res = mysql_real_connect(ms_conn, "localhost", "root", "123456", 19             "db_name", 0, NULL, 0);20     if (ms_res == NULL)21     {22         std::cout << "Error: connect mysql failed: " << mysql_error(ms_conn) << std::endl;23         mysql_close(ms_conn), ms_conn = NULL;24         return 0;25     }26     std::cout << "Info: mysql connect successful." << std::endl;27 28     // ... // 其他動作29     30     // 使用完釋放系統資源31     mysql_close(ms_conn), ms_conn = NULL;32 }

 

MYSQL C API : mysql_real_connect()

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.