必要條件:
1.使用帶mysqlconectionfor c/c++ 的mysql安裝包。
2.在專案屬性中vc++目錄,包含目錄中選擇mysql的include資料夾,庫目錄,選擇mysql的lib資料夾,聯結器輸入的附加依賴項,增加libmysql.lib
c**裡include標頭檔案mysql.h,並且在之前要include標頭檔案winsock.h
mysql *pconn=mysql_init(0);
編譯執行,會報錯找不到libmysql.dll,把mysql的libmysql.dll複製到exe的目錄下。
到此,如果編譯 通過的化就說明環境已經搭建好了,現在執行非查詢語句。
#include#include#include#includeint main()
//防止亂碼,設定和資料庫的編碼一致
if (mysql_query(pconn, "set names gbk"))
//插入測試
if (mysql_query(pconn, "insert into role(role) values('fest')"))
//關閉連線
mysql_close(pconn);
return 0;
}
c語言中連線mysql
1 配置 vc 目錄中新增 包含目錄 c program files mysql mysql server 5.7 include 庫目錄 c program files mysql mysql server 5.7 lib c program files mysql mysql server 5....
linux下C語言連線mysql
linux下c語言連線mysql include include include mysql mysql void doquery m res mysql store result mysql if m res null while m field mysql fetch field m res i...
Linux下C語言連線MySQL
include include include int main if mysql query mysql,select from test num fields mysql num fields result while row mysql fetch row result for i 0 i編譯...