当前位置: 技术问答>linux和unix
服务器将select查询出来的数据直接向客户端发送,怎么改?
来源: 互联网 发布时间:2016-09-19
本文导语: #include #include #include #include #include #include #include #include #include #include #define IPADDR "127.0.0.1" #define PORT 21234 const char *logpath = "./log"; int main() { struct sockaddr_in servaddr,cliaddr; int s...
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define IPADDR "127.0.0.1"
#define PORT 21234
const char *logpath = "./log";
int main()
{
struct sockaddr_in servaddr,cliaddr;
int sockfd,clifd,logfd;
socklen_t clilen;
servaddr.sin_family = AF_INET;
servaddr.sin_port = htons(PORT);
servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
//bzero(&servaddr,sizeof(servaddr));
sockfd=socket(AF_INET,SOCK_STREAM,0);
bind(sockfd,(struct sockaddr *)&servaddr,sizeof(servaddr));
listen(sockfd,20);
printf("aaaaaaaaaaaaaan");
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 -1;
}
/*连接数据库*/
char host[32] = "localhost";
char user[32] = "root";
char passwd[38] = "123456";
char dbc[32] = "mysql";
char getDate[1024];
char id[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 -1;
}
char str[2000];char str1[2000];
char Where_SQL[]="SELECT d.user_id,u.email,d.domain,d.status,v.* FROM domain_vip_status AS v, domains AS d, users AS u WHERE d.id = v.domain_id AND u.id = d.user_id AND d.grade != 'Free' ORDER BY vip_ended_at, email limit 1";
//scanf("%s",str1);
strcat(str,Where_SQL);
//strcat(str,str1);
//sprintf(age,"SELECT * FROM domains where id = %s;");
if(mysql_query(&db,str)!= 0)
{
fprintf(stderr,"Fail to query the db for information.n");
return -1;
}
/*获得查询结果*/
if ((result = mysql_store_result(&db)) == NULL)
{
fprintf(stderr,"Fail to get the result.n");
return -1;
}
char buf[500];
clilen = sizeof(cliaddr);
clifd=accept(sockfd,(struct sockaddr *)&cliaddr,&clilen);
while((row=mysql_fetch_row(result))!= NULL) /*fetching each row*/
{
memset(buf,0,500);
//printf("%sn",row);
buf[5000]=result; //92行
if(clifd
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define IPADDR "127.0.0.1"
#define PORT 21234
const char *logpath = "./log";
int main()
{
struct sockaddr_in servaddr,cliaddr;
int sockfd,clifd,logfd;
socklen_t clilen;
servaddr.sin_family = AF_INET;
servaddr.sin_port = htons(PORT);
servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
//bzero(&servaddr,sizeof(servaddr));
sockfd=socket(AF_INET,SOCK_STREAM,0);
bind(sockfd,(struct sockaddr *)&servaddr,sizeof(servaddr));
listen(sockfd,20);
printf("aaaaaaaaaaaaaan");
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 -1;
}
/*连接数据库*/
char host[32] = "localhost";
char user[32] = "root";
char passwd[38] = "123456";
char dbc[32] = "mysql";
char getDate[1024];
char id[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 -1;
}
char str[2000];char str1[2000];
char Where_SQL[]="SELECT d.user_id,u.email,d.domain,d.status,v.* FROM domain_vip_status AS v, domains AS d, users AS u WHERE d.id = v.domain_id AND u.id = d.user_id AND d.grade != 'Free' ORDER BY vip_ended_at, email limit 1";
//scanf("%s",str1);
strcat(str,Where_SQL);
//strcat(str,str1);
//sprintf(age,"SELECT * FROM domains where id = %s;");
if(mysql_query(&db,str)!= 0)
{
fprintf(stderr,"Fail to query the db for information.n");
return -1;
}
/*获得查询结果*/
if ((result = mysql_store_result(&db)) == NULL)
{
fprintf(stderr,"Fail to get the result.n");
return -1;
}
char buf[500];
clilen = sizeof(cliaddr);
clifd=accept(sockfd,(struct sockaddr *)&cliaddr,&clilen);
while((row=mysql_fetch_row(result))!= NULL) /*fetching each row*/
{
memset(buf,0,500);
//printf("%sn",row);
buf[5000]=result; //92行
if(clifd