//怎么去调用mysql的库的代码
int SendSmsMysql(ParamSmsDB *param, char isEnd){
int error;
char message[1024], sql[4096];
if (isEnd){
if (param->init){
mysql_close(&(param->mysql));
param->init = 0;
}
return 0;
}
if (!param->init){
if (mysql_init(&(param->mysql)) == NULL){
error = __LINE__; ErrorOut(g_Error, "%s error(%d): %s\n", __FUNCTION__, error, mysql_error(&(param->mysql)));
return error;
}
if (mysql_options(&(param->mysql), MYSQL_OPT_RECONNECT, "1")){
error = __LINE__; ErrorOut(g_Error, "%s error(%d): %s\n", __FUNCTION__, error, mysql_error(&(param->mysql)));
return error;
}
if (mysql_real_connect(&(param->mysql), param->server, param->usr, param->pwd, param->dbn, param->port, NULL, 0) == NULL){
error = __LINE__; ErrorOut(g_Error, "%s error(%d): %s\n", __FUNCTION__, error, mysql_error(&(param->mysql)));
return error;
}
if (mysql_ping(&(param->mysql))){
error = __LINE__; ErrorOut(g_Error, "%s error(%d): %s\n", __FUNCTION__, error, mysql_error(&(param->mysql)));
return error;
}
param->init = 1;
}
if (mysql_real_escape_string(&(param->mysql), message, param->cont, strlen(param->cont)) < strlen(param->cont)){
error = __LINE__; ErrorOut(g_Error, "%s error(%d): %s\n", __FUNCTION__, error, mysql_error(&(param->mysql)));
return error;
}
if (param->precv > param->pcont){
sprintf(sql, "%s%s%s%s%s", param->sql, param->cont, param->pcont, param->recv, param->precv);
} else {
sprintf(sql, "%s%s%s%s%s", param->sql, param->recv, param->precv, param->cont, param->pcont);
}
ErrorOut(g_Debug, "%s sql: %s\n", __FUNCTION__, sql);
if (mysql_query(&(param->mysql), sql)){
error = __LINE__; ErrorOut(g_Error, "%s error(%d): %s\n", __FUNCTION__, error, mysql_error(&(param->mysql)));
return error;
}
return 0;
}
分享到:
2015-03-27 14:05
浏览 162
评论