|
2#
楼主 |
发表于 2012-10-12 14:37:18
|
只看该作者
int rc;
int db_connection; // 数据库连接
int query_result; // 查询结果集 MYSQL_RES
char** result_row; // 查询的数据衕
char *server = "192.168.1.250";
char *user = "root";
char *password = "*****";
char *database = "****";
int port = 3306;
int unix_socket = NULL;
int flags = 0;
// 找到libmysql.dll的所在位置.
rc = lr_load_dll("C:\\Program Files\\MySQL\\MySQL Server 5.5\\lib\\libmySQL.dll");
if (rc != 0) {
lr_error_message("Could not load libmysql.dll");
lr_abort();
}
// 创建MySQL对象
db_connection = mysql_init(NULL);
if (db_connection == NULL) {
lr_error_message("Insufficient memory");
lr_abort();
}
// 连接到MySQL数据库
rc = mysql_real_connect(db_connection, server, user, password, database, port, unix_socket, flags);
while(rc == NULL){
rc = mysql_real_connect(db_connection, server, user, password, database, port, unix_socket, flags);
}
// 从数据库查数据
lr_save_string (lr_eval_string("SELECT SQL_NO_CACHE a.*,c.CN_NAME,b.* from CRM_PLATFORM_CUSTOMER "
"a LEFT OUTER JOIN ST_COMPANY_CATEOGRY_SUM b ON "
"a.CR_COMPANY_ID=b.CR_COMPANY_ID LEFT OUTER JOIN MD_CATEGORY "
"c ON b.CR_CATEGORY3_ID=c.CN_ID WHERE a.CR_MGR_GROUP_ID like'001003%' "
"and b.CN_COUNT>0;"),"paramInsertQuery");
rc = mysql_query(db_connection, lr_eval_string("{paramInsertQuery}"));
if (rc = 0) {
}
// 释放MySQL资源
mysql_close(db_connection);
return 0; |
|