日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

mysql c语言教程,C语言调用mysql快速教程(精华篇).pdf

發布時間:2023/12/20 数据库 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 mysql c语言教程,C语言调用mysql快速教程(精华篇).pdf 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

C語言調用mysql快速教程(精華篇).pdf

,使用 語言操作 之前,先在 里頭創建一個數據庫,一個表,在表里頭添加

1 c mysql mysql

數據如下:

創建數據庫,庫名為 cusemysql:

mysql create database cusemysql;

創建表 表名為 , :

mysql use cusemysql;

mysql create table children childno int not null unique,fname varchar 20 ,age int ;

添加一點數據哦:

mysql insert into children values 5, 花 ",10 );

對拉,為了方便起見,把表的大致樣子給大家看看

childno fname age 小星 1 9 大量 2 15

2 ,下面進行具體的操作

插入:insert 好的,我們現編輯一段 c 代碼,取名為 insert.c

///

/* insert.c */

#include #include #include "/usr/local/mysql/include/mysql/mysql.h /*注意哦,上面必須是 mysql.h 的絕對地址,一般在 mysql 下的 include 目錄下,仔細看看

你的在哪里?*/

int main int argc, char *argv[] MYSQL my_connection;

int res;

mysql_init &my_connection ;

/*mysql_real_connect &mysql,host,user,passwd,dbname,0,NULL,0 NULL */

if mysql_real_connect &my_connection, "localhost", "root", ,"cusemysql",0,NULL,CLIENT_FOUND_ROWS printf "Connection successn" ; res mysql_query &my_connection, "insert into children values 10,'Ann',5 " ; if !res printf "Inserted %lu rowsn", unsigned long mysql_affected_rows &my_connection ;

/*里頭的函數返回受表中影響的行數*/ else //分別打印出錯誤代碼及詳細信息 fprintf stderr, "Insert error %d: %sn",mysql_errno &my_connection ,mysql_error &my_connection ; mysql_close &my_connection ; else fprintf stderr, "Connection failedn" ; if mysql_errno &my_connection fprintf stderr, "Connection error %d: %sn",mysql_errno &my_connection ,mysql_error &my_connection ; return EXIT_SUCCESS; /

代碼寫完了,要編譯哦

#gcc -o insert insert.c -L /usr/local/mysql/lib/mysql/*.a -lz

ok,現在我們執行看看

#./insert

Connection Success

Inserted 1 rows

year,果然可以,呵呵

不信到 mysql 下看看表 children 中是否多了剛才插入的那一行數據

注:也許你會問上面 gcc 的命令參數是什么意思阿,其實,我也不太清楚,呵呵

大概是要把 mysql 下的某個特定庫包含進來,可是我不知道具體是個什么庫,所以用*.a 全

部包含進來拉

其實只要包含 mysqlclient.a 就可以,你試試看

更新:update

我們只要把上面的代碼中的

res mysql_query &my_connection, "insert into children values 10,'Ann',5 " ;

換成

res mysql_query &my_connection, "update children set age 20 where childno 5 " ;

即可

上面語句實現的功能是,把編

總結

以上是生活随笔為你收集整理的mysql c语言教程,C语言调用mysql快速教程(精华篇).pdf的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。