c資料庫訪問類
現在誰還有C啊,除非嵌入式編程了
C++還差不多,如果是C++ 又是 Windows系統哪么通過ODBC是啥資料庫都可以支持的
如果是Linux我就不太熟悉了,但至少也會有類於ODBC之類的資料庫引擎
調用對編譯器有要求嗎---肯定沒要求,要不然這個編譯器就沒存在必要,或者這個資料庫介面就沒做的通用化。
❷ 用C語言怎麼實現與資料庫的連接
#include<mysql/mysql.h>
#include<stdio.h>
intmain()
{
MYSQL*conn;
MYSQL_RES*res;
MYSQL_ROWrow;
char*server="localhost";//本地連接
char*user="root";//
char*password="525215980";//mysql密碼
char*database="student";//資料庫名
char*query="select*fromclass";//需要查詢的語句
intt,r;
conn=mysql_init(NULL);
if(!mysql_real_connect(conn,server,user,password,database,0,NULL,0))
{
printf("Errorconnectingtodatabase:%s ",mysql_error(conn));
}else{
printf("Connected... ");
}
t=mysql_query(conn,query);
if(t)
{
printf("Errormakingquery:%s ",mysql_error(conn));
}else{
printf("Querymade... ");
res=mysql_use_result(conn);
if(res)
{
while((row=mysql_fetch_row(res))!=NULL)
{
//printf("num=%d ",mysql_num_fields(res));//列數
for(t=0;t<mysql_num_fields(res);t++)
printf("%8s",row[t]);
printf(" ");
}
}
mysql_free_result(res);
}
mysql_close(conn);
return0;
}
(2)c資料庫訪問類擴展閱讀
C語言使用注意事項:
1、指針是c語言的靈魂,一定要靈活的使用它:
(1)、指針的聲明,創建,賦值,銷毀等
(2)、指針的類型轉換,傳參,回調等
2、遞歸調用也會經常用到:
(1)、遞歸遍歷樹結構
(2)、遞歸搜索
❸ c語言訪問oracle資料庫有幾種方式,哪種最好
SQL SERVER連接oracle資料庫幾種方法--1 方式 --查詢oracle資料庫中的表 SELECT * FROM OPENDATASOURCE( 'MSDAORA', 'Data Source=GE160;User ID=DAIMIN;Password=DAIMIN' )..
❹ 實例講解如何使用C++操作MySQL資料庫類
/* * project: * 通用模塊 ( 用 c++ 處理 mysql 資料庫類,像ADO ) * * description: * * 通過DataBase,RecordSet,Record,Field類,實現對mysql資料庫的操作 * 包括連接、修改、添加、刪除、查詢等等,像ADO一樣操作資料庫,使 * 用方便 * * ( the end of this file have one sample, * welcom to use... ) * * * file:zlb_mysql.h * * author: @ zlb * * time:2005-12-12 * * * --*/ #ifndef ZLB_MYSQL_H #define ZLB_MYSQL_H #include "mysql.h" #include <iostream> #include <vector> #include <string> using namespace std; namespace zlb_mysql{ /* * 欄位操作 */ class Field { public : /* 欄位名稱 */ vector<string> m_name; /* 欄位類型 */ vector<enum_field_types> m_type; public : Field(); ~Field(); /* 是否是數字 */ bool IsNum(int num); /* 是否是數字 */ bool IsNum(string num); /* 是否是日期 */ bool IsDate(int num); /* 是否是日期 */ bool IsDate(string num); /* 是否是字元 */ bool IsChar(int num); /* 是否是字元 */ bool IsChar(string num); /* 是否為二進制數據 */ bool IsBlob(int num); /* 是否為二進制數據 */ bool IsBlob(string num); /* 得到指定欄位的序號 */ int GetField_NO(string field_name); }; /* * 1 單條記錄 * 2 [int ]操作 [""]操作 */ class Record { public: /* 結果集 */ vector<string> m_rs; /* 欄位信息 佔用4位元組的內存 當記錄數很大是回產生性能問題 */ Field *m_field; public : Record(){}; Record(Field* m_f); ~Record(); void SetData(string value); /* [""]操作 */ string operator[](string s); string operator[](int num); /* null值判斷 */ bool IsNull(int num); bool IsNull(string s); /* 用 value tab value 的形式 返回結果 */ string GetTabText(); }; /* * 1 記錄集合 * 2 [int ]操作 [""]操作 * 3 表結構操作 * 4 數據的插入修改 */ class RecordSet { private : /* 記錄集 */ vector<Record> m_s; /* 游標位置*/ unsigned long pos; /* 記錄數 */ int m_recordcount; /* 欄位數 */ int m_field_num; /* 欄位信息 */ Field m_field; MYSQL_RES * res ; MYSQL_FIELD * fd ; MYSQL_ROW row; MYSQL* m_Data ; public : RecordSet(); RecordSet(MYSQL *hSQL); ~RecordSet(); /* 處理返回多行的查詢,返回影響的行數 */ int ExecuteSQL(const char *SQL); /* 得到記錄數目 */ int GetRecordCount(); /* 得到欄位數目 */ int GetFieldNum(); /* 向下移動游標 */ long MoveNext(); /* 移動游標 */ long Move(long length); /* 移動游標到開始位置 */ bool MoveFirst(); /* 移動游標到結束位置 */ bool MoveLast(); /* 獲取當前游標位置 */ unsigned long GetCurrentPos()const; /* 獲取當前游標的對應欄位數據 */ bool GetCurrentFieldValue(const char * sFieldName,char *sValue); bool GetCurrentFieldValue(const int iFieldNum,char *sValue); /* 獲取游標的對應欄位數據 */ bool GetFieldValue(long index,const char * sFieldName,char *sValue); bool GetFieldValue(long index,int iFieldNum,char *sValue); /* 是否到達游標尾部 */ bool IsEof(); /* 返回欄位 */ Field* GetField(); /* 返回欄位名 */ const char * GetFieldName(int iNum); /* 返回欄位類型 */ const int GetFieldType(char * sName); const int GetFieldType(int iNum); /* 返回指定序號的記錄 */ Record operator[](int num); }; /* * 1 負責資料庫的連接關閉 * 2 執行sql 語句(不返回結果) * 3 處理事務 */ class DataBase { public : DataBase(); ~DataBase(); private : /* msyql 連接句柄 */ MYSQL* m_Data; public : /* 返回句柄 */ MYSQL * GetMysql(); /* 連接資料庫 */ int Connect(string host, string user, string passwd, string db, unsigned int port, unsigned long client_flag); /* 關閉資料庫連接 */ void DisConnect(); /* 執行非返回結果查詢 */ int ExecQuery(string sql); /* 測試mysql伺服器是否存活 */ int Ping(); /* 關閉mysql 伺服器 */ int ShutDown(); /* 主要功能:重新啟動mysql 伺服器 */ int ReBoot(); /* * 說明:事務支持InnoDB or BDB表類型 */ /* 主要功能:開始事務 */ int Start_Transaction(); /* 主要功能:提交事務 */ int Commit(); /* 主要功能:回滾事務 */ int Rollback(); /* 得到客戶信息 */ const char * Get_client_info(); /* 主要功能:得到客戶版本信息 */ const unsigned long Get_client_version(); /* 主要功能:得到主機信息 */ const char * Get_host_info(); /* 主要功能:得到伺服器信息 */ const char * Get_server_info(); /*主要功能:得到伺服器版本信息*/ const unsigned long Get_server_version(); /*主要功能:得到 當前連接的默認字元集*/ const char * Get_character_set_name(); /* 主要功能返回單值查詢 */ char * ExecQueryGetSingValue(string sql); /* 得到系統時間 */ const char * GetSysTime(); /* 建立新資料庫 */ int Create_db(string name); /* 刪除制定的資料庫*/ int Drop_db(string name); }; }; #endif //ZLB_MYSQL_H /* * project: * 通用模塊 ( 用 c++ 處理 mysql 資料庫類,像ADO ) * * description: * * 通過DataBase,RecordSet,Record,Field類,實現對mysql資料庫的操作 * 包括連接、修改、添加、刪除、查詢等等,像ADO一樣操作資料庫,使 * 用方便 * * ( the end of this file have one sample, * welcom to use... ) * * * file:zlb_mysql.cpp * * author: @ zlb * * time:2005-12-12 * * * --*/ #include "stdafx.h" #include "zlb_mysql.h" namespace zlb_mysql{ /* +++++++++++++++++++++++++++++++++++++++++++++++++++ */ /* * 欄位操作 */ Field::Field(){} Field::~Field(){} /* * 是否是數字 */ bool Field::IsNum(int num) { if(IS_NUM(m_type[num])) return true; else return false; } /* * 是否是數字 */ bool Field::IsNum(string num) { if(IS_NUM(m_type[GetField_NO(num)])) return true; else return false; } /* * 是否是日期 */ bool Field::IsDate(int num) { if( FIELD_TYPE_DATE == m_type[num] || FIELD_TYPE_DATETIME == m_type[num] ) return true; else return false; } /* 是否是日期 */ bool Field::IsDate(string num) { int temp; temp=GetField_NO(num); if(FIELD_TYPE_DATE == m_type[temp] || FIELD_TYPE_DATETIME == m_type[temp] ) return true; else return false; } /* * 是否是字元 */ bool Field::IsChar(int num) { if(m_type[num]==FIELD_TYPE_STRING || m_type[num]==FIELD_TYPE_VAR_STRING || m_type[num]==FIELD_TYPE_CHAR ) return true; else return false; } /* * 是否是字元 */ bool Field::IsChar(string num) { int temp; temp=this->GetField_NO (num); if(m_type[temp]==FIELD_TYPE_STRING || m_type[temp]==FIELD_TYPE_VAR_STRING || m_type[temp]==FIELD_TYPE_CHAR ) return true; else return false; } /* * 是否為二進制數據 */ bool Field::IsBlob(int num) { if(IS_BLOB(m_type[num])) return true; else return false; } /* * 是否為二進制數據 */ bool Field::IsBlob(string num) { if(IS_BLOB(m_type[GetField_NO(num)])) return true; else return false; } /* * 得到指定欄位的序號 */ int Field::GetField_NO(string field_name) { for(unsigned int i=0;i<m_name.size ();i++) { if(!m_name[i].compare (field_name)) return i; } return -1; } /*-----------------------------------------------------*/ /* +++++++++++++++++++++++++++++++++++++++++++++++++++ */ /* * 1 單條記錄 * 2 [int ]操作 [""]操作 */ Record::Record(Field * m_f) { m_field =m_f; } Record::~Record(){}; void Record::SetData(string value) { m_rs.push_back (value); } /* [""]操作 */ string Record::operator[](string s) { return m_rs[m_field->GetField_NO(s)]; } string Record::operator[](int num) { return m_rs[num]; } /* null值判斷 */ bool Record::IsNull(int num) { if("" == m_rs[num].c_str ()) return true; else return false; } bool Record::IsNull(string s) { if("" == m_rs[m_field->GetField_NO(s)].c_str()) return true; else return false; } /* 主要-功能:用 value tab value 的形式 返回結果 */ string Record::GetTabText() { string temp; for(unsigned int i=0 ;i<m_rs.size();i++) { temp+=m_rs[i]; if(i<m_rs.size ()-1) temp+="\t"; } return temp; } /*-----------------------------------------------------*/ /* +++++++++++++++++++++++++++++++++++++++++++++++++++ */ /* * 1 記錄集合 * 2 [int ]操作 [""]操作 * 3 表結構操作 * 4 數據的插入修改 */ RecordSet::RecordSet() { res = NULL; row = NULL; pos = 0; } RecordSet::RecordSet(MYSQL *hSQL) { res = NULL; row = NULL; m_Data = hSQL; pos = 0; } RecordSet::~RecordSet() { } /* * 處理返回多行的查詢,返回影響的行數 * 成功返回行數,失敗返回-1 */ int RecordSet::ExecuteSQL(const char *SQL) { if ( !mysql_real_query(m_Data,SQL,strlen(SQL))) { //保存查詢結果 res = mysql_store_result(m_Data ); //得到記錄數量 m_recordcount = (int)mysql_num_rows(res) ; //得到欄位數量 m_field_num = mysql_num_fields(res) ; for (int x = 0 ; fd = mysql_fetch_field(res); x++) { m_field.m_name.push_back(fd->name); m_field.m_type.push_back(fd->type); } //保存所有數據 while (row = mysql_fetch_row(res)) { Record temp(&m_field); for (int k = 0 ; k < m_field_num ; k++ ) { if(row[k]==NULL||(!strlen(row[k]))) { temp.SetData (""); } else { temp.SetData(row[k]); } } //添加新記錄 m_s.push_back (temp); } mysql_free_result(res ) ; return m_s.size(); } return -1; } /* * 向下移動游標 * 返回移動後的游標位置 */ long RecordSet::MoveNext() { return (++pos); } /* 移動游標 */ long RecordSet::Move(long length) { int l = pos + length; if(l<0) { pos = 0; return 0; }else { if(l >= m_s.size()) { pos = m_s.size()-1; return pos; }else { pos = l; return pos; } } } /* 移動游標到開始位置 */ bool RecordSet::MoveFirst() { pos = 0; return true; } /* 移動游標到結束位置 */ bool RecordSet::MoveLast() { pos = m_s.size()-1; return true; } /* 獲取當前游標位置 */ unsigned long RecordSet::GetCurrentPos()const { return pos; } /* 獲取當前游標的對應欄位數據 */ bool RecordSet::GetCurrentFieldValue(const char * sFieldName, char *sValue) { strcpy(sValue,m_s[pos][sFieldName].c_str()); return true; } bool RecordSet::GetCurrentFieldValue(const int iFieldNum,char *sValue) { strcpy(sValue,m_s[pos][iFieldNum].c_str()); return true; } /* 獲取游標的對應欄位數據 */ bool RecordSet::GetFieldValue(long index,const char * sFieldName, char *sValue) { strcpy(sValue,m_s[index][sFieldName].c_str()); return true; } bool RecordSet::GetFieldValue(long index,int iFieldNum,char *sValue) { strcpy(sValue,m_s[index][iFieldNum].c_str()); return true; } /* 是否到達游標尾部 */ bool RecordSet::IsEof() { return (pos == m_s.size())?true:false; } /* * 得到記錄數目 */ int RecordSet::GetRecordCount() { return m_recordcount; } /* * 得到欄位數目 */ int RecordSet::GetFieldNum() { return m_field_num; } /* * 返回欄位 */ Field * RecordSet::GetField() { return &m_field; } /* 返回欄位名 */ const char * RecordSet::GetFieldName(int iNum) { return m_field.m_name.at(iNum).c_str(); } /* 返回欄位類型 */ const int RecordSet::GetFieldType(char * sName) { int i = m_field.GetField_NO(sName); return m_field.m_type.at(i); } const int RecordSet::GetFieldType(int iNum) { return m_field.m_type.at(iNum); } /* * 返回指定序號的記錄 */ Record RecordSet::operator[](int num) { return m_s[num]; } /* -------------------------------------------------- */ /* +++++++++++++++++++++++++++++++++++++++++++++++++++ */ /* * 1 負責資料庫的連接關閉 * 2 執行sql 語句(不返回結果) * 3 處理事務 */ DataBase::DataBase() { m_Data = NULL; } DataBase::~DataBase() { if(NULL != m_Data) { DisConnect(); } } /* 返回句柄 */ MYSQL * DataBase::GetMysql() { return m_Data; } /* * 主要功能:連接資料庫 * 參數說明: * 1 host 主機ip地址或者時主機名稱 * 2 user 用戶名 * 3 passwd 密碼 * 4 db 欲連接的資料庫名稱 * 5 port 埠號 * 6 uinx 嵌套字 * 7 client_flag 客戶連接參數 * 返回值: 0成功 -1 失敗 */ int DataBase::Connect(string host, string user, string passwd, string db, unsigned int port, unsigned long client_flag) { if((m_Data = mysql_init(NULL)) && mysql_real_connect( m_Data, host.c_str(), user.c_str(), passwd.c_str(), db.c_str(),port , NULL, client_flag)) { //選擇制定的資料庫失敗 if ( mysql_select_db( m_Data, db.c_str () ) < 0 ) { mysql_close( m_Data) ; return -1 ; } } else { //初始化mysql結構失敗 mysql_close( m_Data ); return -1 ; } //成功 return 0; } /* * 關閉資料庫連接 */ void DataBase::DisConnect( ) { mysql_close(m_Data) ; } /* * 主要功能: 執行非返回結果查詢 * 參數:sql 待執行的查詢語句 * 返回值; n為成功 表示受到影響的行數 -1 為執行失敗 */ int DataBase::ExecQuery(string sql) { if(!mysql_real_query(m_Data,sql.c_str (),(unsigned long)sql.length()) ) { //得到受影響的行數 return (int)mysql_affected_rows(m_Data) ; } else { //執行查詢失敗 return -1; } } /* * 主要功能:測試mysql伺服器是否存活 * 返回值:0 表示成功 -1 失敗 */ int DataBase::Ping() { if(!mysql_ping(m_Data)) return 0; else return -1; } /* * 主要功能:關閉mysql 伺服器 * 返回值;0成功 -1 失敗 */ int DataBase::ShutDown() { if(!mysql_shutdown(m_Data,SHUTDOWN_DEFAULT)) return 0; else return -1; } /* * 主要功能:重新啟動mysql 伺服器 * 返回值;0表示成功 -1 表示失敗 */ int DataBase::ReBoot() { if(!mysql_reload(m_Data)) return 0; else return -1; } /* * 說明:事務支持InnoDB or BDB表類型 */ /* * 主要功能:開始事務 */ int DataBase::Start_Transaction() { if(!mysql_real_query(m_Data, "START TRANSACTION" , (unsigned long)strlen("START TRANSACTION") )) { return 0; } else //執行查詢失敗 return -1; } /* * 主要功能:提交事務 * 返回值:0 表示成功 -1 表示失敗 */ int DataBase::Commit() { if(!mysql_real_query( m_Data, "COMMIT", (unsigned long)strlen("COMMIT") ) ) { return 0; } else //執行查詢失敗 return -1; } /* * 主要功能:回滾事務 * 返回值:0 表示成功 -1 表示失敗 */ int DataBase::Rollback() { if(!mysql_real_query(m_Data, "ROLLBACK", (unsigned long)strlen("ROLLBACK") ) ) return 0; else //執行查詢失敗 return -1; } /* 得到客戶信息 */ const char * DataBase::Get_client_info() { return mysql_get_client_info(); } /*主要功能:得到客戶版本信息*/ const unsigned long DataBase::Get_client_version() { return mysql_get_client_version(); } /* 主要功能:得到主機信息 */ const char * DataBase::Get_host_info() { return mysql_get_host_info(m_Data); } /* 主要功能:得到伺服器信息 */ const char * DataBase::Get_server_info() { return mysql_get_server_info( m_Data ); } /* 主要功能:得到伺服器版本信息 */ const unsigned long DataBase::Get_server_version() { return mysql_get_server_version(m_Data); } /*主要功能:得到 當前連接的默認字元集*/ const char * DataBase::Get_character_set_name() { return mysql_character_set_name(m_Data); } /* * 主要功能返回單值查詢 */ char * DataBase::ExecQueryGetSingValue(string sql) { MYSQL_RES * res; MYSQL_ROW row ; char *p = NULL; if(!mysql_real_query( m_Data, sql.c_str(),(unsigned long)sql.length())) { //保存查詢結果 res = mysql_store_result( m_Data ) ; row = mysql_fetch_row( res ) ; p = ((row[0]==NULL)||(!strlen(row[0])))?"-1":row[0]; mysql_free_result( res ) ; } else //執行查詢失敗 p = "-1"; return p; } /* * 得到系統時間 */ const char * DataBase::GetSysTime() { return ExecQueryGetSingValue("select now()"); } /* * 主要功能:建立新資料庫 * 參數:name 為新資料庫的名稱 * 返回:0成功 -1 失敗 */ int DataBase::Create_db(string name) { string temp ; temp="CREATE DATABASE "; temp+=name; if(!mysql_real_query( m_Data,temp.c_str () , (unsigned long)temp.length ()) ) return 0; else //執行查詢失敗 return -1; } /* * 主要功能:刪除制定的資料庫 * 參數:name 為欲刪除資料庫的名稱 * 返回:0成功 -1 失敗 */ int DataBase::Drop_db(string name) { string temp ; temp="DROP DATABASE "; temp+=name; if(!mysql_real_query( m_Data,temp.c_str () , (unsigned long)temp.length ()) ) return 0; else //執行查詢失敗 return -1; } /*-----------------------------------------------------*/ }; /* * 使用例子 */ #include "zlb_mysql.h" using namespace std; void main() { zlb_mysql::DataBase zlb; //連接資料庫 if(-1 == zlb.Connect("localhost"/*本地資料庫,可以是遠程 ip*/, "root"/*用戶名*/,"apple"/*密碼*/, "test"/*資料庫名*/, 0,0/*兩個標志,mysql文檔有說明,一般為0*/)) { std::cout<<"connect failed "<<std::endl; } else { std::cout<<"connect success"<<std::endl; } //通過返回的資料庫句柄,建立記錄急,你可以通過返回的這個句柄建立多個記錄急 zlb_mysql::RecordSet rs(zlb.GetMysql()); rs.ExecuteSQL("select * from testtable");//這個語句大家都知道是什麼意思了 cout<<rs.GetRecordCount()/*返回的總的記錄數*/<<endl; cout<<rs.GetFieldNum()/*返回的總的欄位數*/<<endl; cout<<rs[0].GetTabText()/*返回第一條記錄,你也可以rs[1].GetTabText() 如果你有多條記錄, */ <<endl; /*實現遍列,也可以使用後面的遍列方式*/ for(int i=0;i<rs.GetRecordCount();++i) { for(int j =0;j<rs.GetFieldNum();++j) cout<<rs[i][j]; cout<<endl; } zlb_mysql::Field *fd = rs.GetField();/*你可以通過這樣的方式,獲取欄位的信息*/ cout<<fd->GetField_NO("Password")/*返回我表裡的 Password 欄位的位置,不 是記錄的位置*/ <<endl; cout<<rs[0]["Password"]<<endl;/*輸出第0行第Password列的值*/ cout<<rs[0][fd->GetField_NO("Password")]<<endl;/*你也可以這樣*/ cout<<rs.GetFieldName(0)/*獲取欄位的名字*/<<endl; cout<<rs.GetFieldType("UserName")/*獲取欄位的類型,是mysql里定義的*/<<endl; cout<<rs.GetCurrentPos()/*獲取當前記錄的位置*/<<endl; char s[50]; rs.GetCurrentFieldValue(1,s);/*獲取當前記錄對應欄位的值*/ cout<<s<<endl; cout<<rs.Move(1)<<endl;/*移動游標,正數往前 負數往後*/ cout<<rs.GetCurrentPos()<<endl; rs.GetCurrentFieldValue(1,s); cout<<s<<endl; rs.MoveFirst();/*移動游標到最前*/ while(!rs.IsEof()/*判斷是否到達游標尾,實現遍列*/) { rs.GetCurrentFieldValue("UserName",s); cout<<s<<"\t"; rs.GetCurrentFieldValue("Password",s); cout<<s<<"\t
"; rs.MoveNext(); } rs.GetFieldValue(0,"UserName",s);/*獲取指定行 的記錄值*/ cout<<s<<"\t"; rs.GetFieldValue(0,"Password",s); cout<<s<<"\t
"; }
❺ c/c++寫伺服器一般用什麼方式訪問資料庫的
要做伺服器端的話資料庫就是放在你的伺服器上的, 資料庫會提供相應的訪問介面, 具體使用方式可以搜一下"C++連接資料庫"之類的
http是客戶端訪問伺服器才用得到, 直接操作資料庫的總是伺服器端而不是客戶端
❻ 用c語言怎麼連接資料庫呢
25.2.2. C API函數概述
這里歸納了C API可使用的函數,並在下一節詳細介紹了它們。請參見25.2.3節,「C API函數描述」。
函數
描述
mysql_affected_rows()
返回上次UPDATE、DELETE或INSERT查詢更改/刪除/插入的行數。
mysql_autocommit()
切換 autocommit模式,ON/OFF
mysql_change_user()
更改打開連接上的用戶和資料庫。
mysql_charset_name()
返回用於連接的默認字元集的名稱。
mysql_close()
關閉伺服器連接。
mysql_commit()
提交事務。
mysql_connect()
連接到MySQL伺服器。該函數已不再被重視,使用mysql_real_connect()取代。
mysql_create_db()
創建資料庫。該函數已不再被重視,使用SQL語句CREATE DATABASE取而代之。
mysql_data_seek()
在查詢結果集中查找屬性行編號。
mysql_debug()
用給定的字元串執行DBUG_PUSH。
mysql_drop_db()
撤銷資料庫。該函數已不再被重視,使用SQL語句DROP DATABASE取而代之。
mysql_mp_debug_info()
讓伺服器將調試信息寫入日誌。
mysql_eof()
確定是否讀取了結果集的最後一行。該函數已不再被重視,可以使用mysql_errno()或mysql_error()取而代之。
mysql_errno()
返回上次調用的MySQL函數的錯誤編號。
mysql_error()
返回上次調用的MySQL函數的錯誤消息。
mysql_escape_string()
為了用在SQL語句中,對特殊字元進行轉義處理。
mysql_fetch_field()
返回下一個表欄位的類型。
mysql_fetch_field_direct()
給定欄位編號,返回表欄位的類型。
mysql_fetch_fields()
返回所有欄位結構的數組。
mysql_fetch_lengths()
返回當前行中所有列的長度。
mysql_fetch_row()
從結果集中獲取下一行
mysql_field_seek()
將列游標置於指定的列。
mysql_field_count()
返回上次執行語句的結果列的數目。
mysql_field_tell()
返回上次mysql_fetch_field()所使用欄位游標的位置。
mysql_free_result()
釋放結果集使用的內存。
mysql_get_client_info()
以字元串形式返回客戶端版本信息。
mysql_get_client_version()
以整數形式返回客戶端版本信息。
mysql_get_host_info()
返回描述連接的字元串。
mysql_get_server_version()
以整數形式返回伺服器的版本號。
mysql_get_proto_info()
返回連接所使用的協議版本。
mysql_get_server_info()
返回伺服器的版本號。
mysql_info()
返回關於最近所執行查詢的信息。
mysql_init()
獲取或初始化MYSQL結構。
mysql_insert_id()
返回上一個查詢為AUTO_INCREMENT列生成的ID。
mysql_kill()
殺死給定的線程。
mysql_library_end()
最終確定MySQL C API庫。
mysql_library_init()
初始化MySQL C API庫。
mysql_list_dbs()
返回與簡單正則表達式匹配的資料庫名稱。
mysql_list_fields()
返回與簡單正則表達式匹配的欄位名稱。
mysql_list_processes()
返回當前伺服器線程的列表。
mysql_list_tables()
返回與簡單正則表達式匹配的表名。
mysql_more_results()
檢查是否還存在其他結果。
mysql_next_result()
在多語句執行過程中返回/初始化下一個結果。
mysql_num_fields()
返回結果集中的列數。
mysql_num_rows()
返回結果集中的行數。
mysql_options()
為mysql_connect()設置連接選項。
mysql_ping()
檢查與伺服器的連接是否工作,如有必要重新連接。
mysql_query()
執行指定為「以Null終結的字元串」的SQL查詢。
mysql_real_connect()
連接到MySQL伺服器。
mysql_real_escape_string()
考慮到連接的當前字元集,為了在SQL語句中使用,對字元串中的特殊字元進行轉義處理。
mysql_real_query()
執行指定為計數字元串的SQL查詢。
mysql_refresh()
刷新或復位表和高速緩沖。
mysql_reload()
通知伺服器再次載入授權表。
mysql_rollback()
回滾事務。
mysql_row_seek()
使用從mysql_row_tell()返回的值,查找結果集中的行偏移。
mysql_row_tell()
返回行游標位置。
mysql_select_db()
選擇資料庫。
mysql_server_end()
最終確定嵌入式伺服器庫。
mysql_server_init()
初始化嵌入式伺服器庫。
mysql_set_server_option()
為連接設置選項(如多語句)。
mysql_sqlstate()
返回關於上一個錯誤的SQLSTATE錯誤代碼。
mysql_shutdown()
關閉資料庫伺服器。
mysql_stat()
以字元串形式返回伺服器狀態。
mysql_store_result()
檢索完整的結果集至客戶端。
mysql_thread_id()
返回當前線程ID。
mysql_thread_safe()
如果客戶端已編譯為線程安全的,返回1。
mysql_use_result()
初始化逐行的結果集檢索。
mysql_warning_count()
返回上一個SQL語句的告警數。 詳見:http://dev.mysql.com/doc/refman/5.1/zh/apis.html#c-api-function-overview
http://dev.mysql.com/doc/refman/5.0/en/c.html
❼ 請問c語言如何訪問資料庫
那要看你訪問什麼資料庫了,一般的資料庫都會提供介面給你,具體的資料庫要去查他們的文檔
❽ c語言操作資料庫有哪些
都是可以的C/C++與資料庫交互,像mssql/mysql/oracle
等。一般都有成熟的第三方庫。這些庫裡面無非就是封裝了與資料庫通訊的方式和通訊協議。
❾ 如何在c語言中編程訪問資料庫
第一種,資料庫廠商提供的C變種,比如oracle的proc-c,簡單點說,就是在C嵌入sql代碼來實現資料庫的訪問。
第二種,資料庫廠商提供的api,比如oracle的OCI。