bitsCN.com
(一)code
#include
#include
#include
#include
#include
#include
#define MAX_QUERY_LEN 1024
#define MAX_QUERY_COUNT 2
#define PRINT_MYSQL_ERROR(mysql) fprintf(stderr, "mysql-error:%s/n", mysql_error(mysql))
typedef struct prop_global{
MYSQL *mysql;
char *db_host;
char *db_user;
char *db_pwd;
char *db_name;
char query[MAX_QUERY_LEN];
int order_id;
}prop_global_t;
static prop_global_t *g_p;
int prop_init(const char *host, const char *user, const char *pwd, const char *db){
prop_global_t *y=(prop_global_t *) malloc( sizeof(*y));
y->mysql = mysql_init(NULL);
if( NULL == y->mysql ){
PRINT_MYSQL_ERROR( y->mysql );
return -1;
}
// printf("mysql %s, %s, %s, %s/n", host, user, pwd, db);
if( NULL == mysql_real_connect( y->mysql, host, user, pwd, db, 0, NULL, 0 ) ){
PRINT_MYSQL_ERROR( y->mysql );
return -1;
}
y->db_host = strdup(host);
y->db_user = strdup(user);
y->db_pwd = strdup(pwd );
y->db_name = strdup( db);
y->order_id = 1;
g_p = y;
//printf("mysql init ok/n");
return 0;
}
int safe_query( prop_global_t *y, const char *query, int len){
int i;
int errno;
//printf("sql: %d %s/n", len, query );
for( i=0; i errno = mysql_real_query(y->mysql, query, len); switch( errno ){ case 0: return 0; case CR_SERVER_GONE_ERROR: case CR_SERVER_LOST: mysql_close( y->mysql ); y->mysql = mysql_init(NULL); if( NULL == mysql_real_connect( y->mysql, y->db_host, y->db_user, y->db_pwd, y->db_name, 0, NULL, 0 ) ){ PRINT_MYSQL_ERROR( y->mysql ); return -1; } break; default: PRINT_MYSQL_ERROR( y->mysql ); return -1; } } return -1; } int get_lzddz_num(void){ int n; int rownum = 0; //MYSQL_ROW row; MYSQL_RES *res = NULL; prop_global_t *y = g_p; int r = -1; n = snprintf(y->query, MAX_QUERY_LEN , "select userid,matchid,matchseq ,userseq , score, state, takecoin , token, signupcond,site, rtime from t_jj_user_match where matchid = 6684674 or matchid = 6684675 or matchid = 6684676" ); if( safe_query(y, y->query, n )){ printf("err:%d/n", __LINE__); return r; } res = mysql_store_result(y->mysql); if( NULL == res ){ printf("err:%d/n", __LINE__); return r; } rownum = mysql_num_rows( res ); /* printf("lzddz num = %d/n", rownum ); if( rownum > 0 ){ while( (row = mysql_fetch_row(res) ) ) { printf("%d/t", atoi( row[0] )); //userid printf("%d/t", atoi( row[1] )); //matchid printf("%d/t", atoi( row[2] )); //matchseq printf("%d/t", atoi( row[3] )); //userseq printf("%d/t", atoi( row[4] )); //score printf("%d/t", atoi( row[5] )); //state printf("%d/t", atoi( row[6] )); //takecoin printf("%d/t", atoi( row[7] )); //token printf("%d/t", atoi( row[8] )); //signupcond printf("%d/t", atoi( row[9] )); //site printf("%d/t", atoi( row[10] )); // rtime printf("/n"); } } */ mysql_free_result(res); system("date"); printf("lzddz num = %d/n", rownum ); return rownum; } void prop_release( void ){ prop_global_t *y = g_p; mysql_close( y->mysql ); free( y->db_host); free( y->db_user); free( y->db_pwd ); free( y->db_name); } int main(void){ int ret = 0; ret = prop_init( "41.15.11.59", "lhm", "1234567lhm", "db_jj"); if( 0 == ret ){ get_lzddz_num(); prop_release(); } return 0; } (二)Makefile [lvhongmin@AY1401201736089361adZ database]$ cat Makefile FLAGS = -O2 -g -Wpointer-arith -Wstrict-prototypes -lm -W -Wall LIB = -lpthread -lmysqlclient INCLUDE_PATH = /usr/include/mysql CC = gcc all:lhm.exe lhm.exe:lhm_query.c $(CC) -o $@ ${LIB} ${FLAGS} -L /usr/lib64/mysql -I ${INCLUDE_PATH} lhm_query.c clean: rm lhm.exe

MySQL使用的是GPL許可證。 1)GPL許可證允許自由使用、修改和分發MySQL,但修改後的分發需遵循GPL。 2)商業許可證可避免公開修改,適合需要保密的商業應用。

選擇InnoDB而不是MyISAM的情況包括:1)需要事務支持,2)高並發環境,3)需要高數據一致性;反之,選擇MyISAM的情況包括:1)主要是讀操作,2)不需要事務支持。 InnoDB適合需要高數據一致性和事務處理的應用,如電商平台,而MyISAM適合讀密集型且無需事務的應用,如博客系統。

在MySQL中,外鍵的作用是建立表與表之間的關係,確保數據的一致性和完整性。外鍵通過引用完整性檢查和級聯操作維護數據的有效性,使用時需注意性能優化和避免常見錯誤。

MySQL中有四種主要的索引類型:B-Tree索引、哈希索引、全文索引和空間索引。 1.B-Tree索引適用於範圍查詢、排序和分組,適合在employees表的name列上創建。 2.哈希索引適用於等值查詢,適合在MEMORY存儲引擎的hash_table表的id列上創建。 3.全文索引用於文本搜索,適合在articles表的content列上創建。 4.空間索引用於地理空間查詢,適合在locations表的geom列上創建。

toCreateAnIndexinMysql,usethecReateIndexStatement.1)forasingLecolumn,使用“ createIndexIdx_lastNameEnemployees(lastName); 2)foracompositeIndex,使用“ createIndexIndexIndexIndexIndexDx_nameOmplayees(lastName,firstName,firstName);” 3)forauniqe instex,creationexexexexex,

MySQL和SQLite的主要區別在於設計理念和使用場景:1.MySQL適用於大型應用和企業級解決方案,支持高性能和高並發;2.SQLite適合移動應用和桌面軟件,輕量級且易於嵌入。

MySQL中的索引是數據庫表中一列或多列的有序結構,用於加速數據檢索。 1)索引通過減少掃描數據量提升查詢速度。 2)B-Tree索引利用平衡樹結構,適合範圍查詢和排序。 3)創建索引使用CREATEINDEX語句,如CREATEINDEXidx_customer_idONorders(customer_id)。 4)複合索引可優化多列查詢,如CREATEINDEXidx_customer_orderONorders(customer_id,order_date)。 5)使用EXPLAIN分析查詢計劃,避

在MySQL中使用事務可以確保數據一致性。 1)通過STARTTRANSACTION開始事務,執行SQL操作後用COMMIT提交或ROLLBACK回滾。 2)使用SAVEPOINT可以設置保存點,允許部分回滾。 3)性能優化建議包括縮短事務時間、避免大規模查詢和合理使用隔離級別。


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

SecLists
SecLists是最終安全測試人員的伙伴。它是一個包含各種類型清單的集合,這些清單在安全評估過程中經常使用,而且都在一個地方。 SecLists透過方便地提供安全測試人員可能需要的所有列表,幫助提高安全測試的效率和生產力。清單類型包括使用者名稱、密碼、URL、模糊測試有效載荷、敏感資料模式、Web shell等等。測試人員只需將此儲存庫拉到新的測試機上,他就可以存取所需的每種類型的清單。

mPDF
mPDF是一個PHP庫,可以從UTF-8編碼的HTML產生PDF檔案。原作者Ian Back編寫mPDF以從他的網站上「即時」輸出PDF文件,並處理不同的語言。與原始腳本如HTML2FPDF相比,它的速度較慢,並且在使用Unicode字體時產生的檔案較大,但支援CSS樣式等,並進行了大量增強。支援幾乎所有語言,包括RTL(阿拉伯語和希伯來語)和CJK(中日韓)。支援嵌套的區塊級元素(如P、DIV),

SublimeText3 Linux新版
SublimeText3 Linux最新版

記事本++7.3.1
好用且免費的程式碼編輯器

DVWA
Damn Vulnerable Web App (DVWA) 是一個PHP/MySQL的Web應用程序,非常容易受到攻擊。它的主要目標是成為安全專業人員在合法環境中測試自己的技能和工具的輔助工具,幫助Web開發人員更好地理解保護網路應用程式的過程,並幫助教師/學生在課堂環境中教授/學習Web應用程式安全性。 DVWA的目標是透過簡單直接的介面練習一些最常見的Web漏洞,難度各不相同。請注意,該軟體中