#include <string>
#include <iostream>
#include <strstream>
#include <fstream> //ifstream fin("ent_list");
#include "/usr/local/mysql/include/mysql/mysql.h"
const char mysqlServer[20] = "172.16.1.77";
//const char mysqlServer[20] = "10.88.15.114";
const char user[20]="web";
const char password[20]="sinatest";
const char database[20]="enterprise";
unsigned int port=3306;
using namespace std;
//去掉读出的一行的前后空格
void trim(string& str)
{
str.erase(str.find_last_not_of(' ')+1, string::npos);
str.erase(0, str.find_first_not_of(' '));
}
//去前后空格函数结束
int main()//main函数体
{
MYSQL myData;
MYSQL_RES *res;
MYSQL_FIELD *fd;
MYSQL_ROW row;
int i,j,rowCount = 0,colCount = 0;
char query[1024];
mysql_init( &myData );
if(!mysql_real_connect( &myData, mysqlServer, user, password, database,port,NULL,0))
{
printf("connect mysql error!\n");
}
//读取文本
ifstream fin("ent_list");
string str;
while(getline(fin,str))
{
trim(str);//去掉读出的一行前后空格
//cout<<str<<"\n";
strcpy(query,"select path from enterprise where enterpriseid=");
strcat(query,str.c_str());
//fprintf(stderr,"FILE=%s,LINE=%d,query=%s\n",__FILE__,__LINE__,query);
if( mysql_query(&myData, query) != 0 )
{
printf("query error!\n");
return 0;
}else{
res = mysql_store_result( &myData );
rowCount = (int) mysql_num_rows( res );
colCount = (int) mysql_num_fields( res );
//printf(" result: %d records found\n fields: %d \n", rowCount, colCount);
row = mysql_fetch_row( res );
for(i = 0; i < rowCount; i++)
{
for( j = 0; j < colCount; j++)
{
cout <<"cd ";
printf("%s", row[j] );
cout <<";touch .expire;";
cout<<"\n";
}
}
}
}
}
#include <iostream>
#include <strstream>
#include <fstream> //ifstream fin("ent_list");
#include "/usr/local/mysql/include/mysql/mysql.h"
const char mysqlServer[20] = "172.16.1.77";
//const char mysqlServer[20] = "10.88.15.114";
const char user[20]="web";
const char password[20]="sinatest";
const char database[20]="enterprise";
unsigned int port=3306;
using namespace std;
//去掉读出的一行的前后空格
void trim(string& str)
{
str.erase(str.find_last_not_of(' ')+1, string::npos);
str.erase(0, str.find_first_not_of(' '));
}
//去前后空格函数结束
int main()//main函数体
{
MYSQL myData;
MYSQL_RES *res;
MYSQL_FIELD *fd;
MYSQL_ROW row;
int i,j,rowCount = 0,colCount = 0;
char query[1024];
mysql_init( &myData );
if(!mysql_real_connect( &myData, mysqlServer, user, password, database,port,NULL,0))
{
printf("connect mysql error!\n");
}
//读取文本
ifstream fin("ent_list");
string str;
while(getline(fin,str))
{
trim(str);//去掉读出的一行前后空格
//cout<<str<<"\n";
strcpy(query,"select path from enterprise where enterpriseid=");
strcat(query,str.c_str());
//fprintf(stderr,"FILE=%s,LINE=%d,query=%s\n",__FILE__,__LINE__,query);
if( mysql_query(&myData, query) != 0 )
{
printf("query error!\n");
return 0;
}else{
res = mysql_store_result( &myData );
rowCount = (int) mysql_num_rows( res );
colCount = (int) mysql_num_fields( res );
//printf(" result: %d records found\n fields: %d \n", rowCount, colCount);
row = mysql_fetch_row( res );
for(i = 0; i < rowCount; i++)
{
for( j = 0; j < colCount; j++)
{
cout <<"cd ";
printf("%s", row[j] );
cout <<";touch .expire;";
cout<<"\n";
}
}
}
}
}
作者:jackxiang@向东博客 专注WEB应用 构架之美 --- 构架之美,在于尽态极妍 | 应用之美,在于药到病除
地址:https://jackxiang.com/post/951/
版权所有。转载时必须以链接形式注明作者和原始出处及本声明!
评论列表