C語言寫資料庫(二)

2022-03-19 12:31:46 字數 866 閱讀 1740

簡單的實現增刪查改的操作後,實現了乙個先讀寫其中乙個表的某兩項內容,再把相關字元段寫入到另外一張表中去。涉及到查詢和插入兩個步驟。

其中還涉及到漢字的讀寫和插入,會有字元的操作產生亂碼。所以要先保證mysql的漢字字元編碼,linux終端字元編碼都是統一的。

/*

** queryandinsert

***/

#include

#include

#include

#include

"mysql.h

"int

main()

else

else}}

printf(

"taskid = %s, taskname = %s\n

",taskid,taskname);

sprintf(insert,

"insert into environmentrealdata (taskid,taskname) values(\'%s\',\'%s\');

",taskid,taskname);

printf(

"insert = %s\n

",insert);

//insert

if(mysql_real_query(&mysql,insert,(unsigned int

)strlen(insert)))

else

mysql_close(&mysql);

return0;

}

gcc編譯:gcc queryandinsert.c -o queryandinsert -i /usr/inlcude/mysql -l /usr/lib/mysql -lmysqlclient

c語言寫入mysql C語言寫資料庫(三)

遇到的問題以及解決思路方法 1.外部匯入資料庫檔案 進入mysql,建立資料庫sh robot source home exbot sh robot.sql 檢視資料庫編碼格式 show variables like char 2.資料庫插入操作 查詢存在該錶是否存在 show tables 不存在...

練習寫資料庫

create database factorywork gouse factorywork gocreate table employee employeeid int not null primary key,employeename char 20 not null,employee char ...

易語言寫資料到MySQL 易語言讀寫資料庫操作詳解

1.實現效果 3.原始碼 版本 2 支援庫 sqlite3 支援庫 spec 支援庫 iext 程式集 視窗程式集 啟動視窗 程式集變數 test資料庫,sqlite資料庫 程式集變數 student表,sqlite表 子程式 按鈕 插入資料 被單擊 如果 test資料庫.開啟 e 易語言 自己做的...