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

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

mysql segmentation fault_mysql Segmentation fault的问题,求教

發(fā)布時(shí)間:2024/10/8 数据库 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 mysql segmentation fault_mysql Segmentation fault的问题,求教 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

intUserByEmail(charstr1[],intclient){charbuffer[500];MYSQLdb;/*connector*/MYSQL_RES*result;/*resultbuffer*/MYSQL_ROWrow;/*onerowoftheresult*/inti;/*初始化mysql*/if(mysql_...

int UserByEmail(char str1[],int client)

{

char buffer[500];

MYSQL db;/*connector*/

MYSQL_RES * result;/*result buffer*/

MYSQL_ROW row;/*one row of the result*/

int i;

/*初始化mysql*/

if(mysql_init(&db)==NULL)

{

fprintf(stderr,"Fail to initialize the db.\n");

return;

}

/*連接數(shù)據(jù)庫*/

char host[32] = "localhost";

char user[32] = "sxm";

char passwd[38] = "123456";

char dbc[32] = "mysql";

char getDate[1024];

char domain[2000];

char s[2000];

memset(getDate,0,1024);

if (NULL == (mysql_real_connect(&db,host,user,passwd,dbc,0,NULL,0)))

{

fprintf(stderr,"Connect to mysql Error:%s!",mysql_error(&db));

return;

}

char str[2000];

char str3[]="'";

memset(str,0,2000);

char Where_SQL[]="select * from users where email='";

strcat(str,Where_SQL);

strcat(str,str1);

strcat(str,str3);

printf("str=%s\n",str);

if(mysql_query(&db,str)!= 0)

{ // select();

fprintf(stderr,"Fail to query the db for information.\n");

return;

}

/*獲得查詢結(jié)果*/

result = mysql_store_result(&db);

if(result)

{

int num_fields;

num_fields = mysql_num_rows(result);

if(num_fields>0)

{

printf("get the result\n");

}

else

{

return;

}

}

else

{

fprintf(stderr,"Fail to get the result.\n");

return;

}

struct json_object *dal_data;

dal_data = json_object_new_object();

while((row=mysql_fetch_row(result)) != NULL)/*fetching each row*/

{

json_object_object_add(dal_data, "id", json_object_new_string(row[0]));

json_object_object_add(dal_data, "email", json_object_new_string(row[1]));

json_object_object_add(dal_data, "password", json_object_new_string(row[2]));

json_object_object_add(dal_data, "status", json_object_new_string(row[3]));

memset(buffer,0,500);

printf("\necho json_encode(dal_data);\n\n%s\n\n",json_object_to_json_string(dal_data));

strcat(buffer,json_object_to_json_string(dal_data));

strcat(buffer,"\n");

ssl_write(client,buffer);

}

json_object_put(dal_data);

mysql_free_result(result);

mysql_close(&db);

close(client);

}

上邊是C-mysql一個(gè)api,程序在本機(jī)跑了好幾天都沒問題,但是拿到線上測(cè)試的時(shí)候發(fā)現(xiàn)程序跑到mysql_close(&db);(上邊已經(jīng)標(biāo)出)這一句的時(shí)候就斷了,錯(cuò)誤提示:Segmentation fault

上線之后程序就改了個(gè)mysql的user和passwd,其他的都沒改,本機(jī)跑沒出現(xiàn)過問題

一上線就斷了,把mysql_close(&db);這句注釋掉之后程序就沒Segmentation fault的錯(cuò)誤提示了,但是mysql又不能不關(guān);

我查過,網(wǎng)上說是 result初始化的問題,可是我初始化了,本機(jī)怎么就沒問題?

個(gè)人覺得是不是線上環(huán)境和本機(jī)環(huán)境的差別?

虛心求教~~

linux-C-myql

展開

總結(jié)

以上是生活随笔為你收集整理的mysql segmentation fault_mysql Segmentation fault的问题,求教的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。