C C 呼叫mysql介面例項1

2021-07-24 20:34:51 字數 2618 閱讀 5887

例項1:

#include 

#include

#include

#include

int main()

else

system("pause");

return 0;

}

函式:

mysql *mysql_real_connect(mysql *mysql, const char *host, const char *user, const char *passwd, const char *db, unsigned intport, const char *unix_socket, unsigned longclient_flag)

引數的指定方式如下:

第1個引數應是已有

mysql

結構的位址。呼叫

mysql_real_connect()

之前,必須呼叫

mysql_init()

來初始化

mysql

結構。通過

mysql_options

()呼叫,可更改多種連線選項。

「host」的值必須是

主機名或ip位址。如果

「host」

是null

或字串"localhost"

,連線將被視為與

本地主機

的連線。如果作業系統支援

套接字(unix)或

命名管道

(windows),將使用它們而不是

tcp/ip

連線到伺服器。

「user」引數包含使用者的

mysql

登入id

。如果「user」

是null

或空字串

"",使用者將被視為當前使用者。在

unix

環境下,它是當前的

登入名。在windows odbc下,必須明確指定當前使用者名稱。

「passwd」引數包含使用者的密碼。如果

「passwd」

是null

,僅會對該使用者的(擁有

1個空密碼欄位的)使用者表中的條目進行匹配檢查。這樣,

資料庫管理員

就能按特定的方式設定mysql許可權系統,根據使用者是否擁有指定的密碼,使用者將獲得不同的許可權。

呼叫mysql_real_connect()之前,不要嘗試加密密碼,密碼加密將由客戶端

api自動處理。

「db」是資料庫名稱。如果db為

null

,連線會將預設的資料庫設為該值。

如果「port」不是

0,其值將用作

tcp/ip

連線的埠號

。注意,「host」引數決定了連線的型別。

如果unix_socket不是

null

,該字串描述了應使用的

套接字或

命名管道

。注意,「host」引數決定了連線的型別。

client_flag的值通常為

0,但是,也能將其設定為下述標誌的組合,以允許特定功能:

本機中存在乙個名為:students資料庫。我們可以看到連線資料庫成功。

例項2:

#include 

#include

#include

#include

int main()

else

if (mysql_query(mysql,"insert into t_users(username,password) values('qq','aa123')"))

else

mysql_close(mysql);

//程式最後必須關閉mysql伺服器

system("pause");

return 0;

}

mysql_query(mysql,"insert into t_users(username,password) values('qq','aa123')")

//執行插入語句

在程式編譯執行之前,我們現在"students"資料庫中建立乙個名為t_users的表

然後,程式執行結果:

然後查詢資料庫中表中的字段資料:

我們看到的確操作成功。

RESTFUL介面呼叫例項

廢話不多說,直接看 page page new page page.setpagenum 1 page.setpagesize 1 mapparams new hashmap params.put ids ids params.put page page jsonobject jsonobj new...

小程式呼叫介面例項

wx.request method post header complete function res if res null res.data null success function res 在這裡對js進行簡單的解釋,wcss和wxml 就不奉上了!url 這個是要請求的介面位址 data ...

Linux使用Python呼叫C C 介面

c 標頭檔案 pyext.h 01 ifndef pyext h 02 define pyext h 03 include 04 05classpyext 06 09 pyext 10 11staticvoidfoo 12 13 14 endif pyext h main.cpp 01 includ...