#include #include
MYSQL mysql;
int main(int argc,char *argv[])
{
char host[32]="localhost";
char user[32]="root";
char passwd[32]="";
char dbname[32]="";
char ip[65];
if (argc != 2)
{
printf("usage: %s ip\n",argv[0]);
return -1;
}
sprintf(ip,argv[1]);
if( mysql_init(&mysql) == NULL )
{
printf("inital mysql handle error\n");
return 1;
}
if (mysql_real_connect(&mysql,host,user,passwd,dbname,0,NULL,0) == NULL)
{
printf("Failed to connect to database: Error: %s\n",mysql_error(&mysql));
return 1;
}
MYSQL_ROW m_row;
MYSQL_RES *m_res;
char sql[1024];
int res=1;
int t,r;
sprintf(sql,"select password from t_passwd_info where host='%s' and username='root'",ip);
if(mysql_query(&mysql,sql) != 0)
{
printf("select ps_info Error: %s\n",mysql_error(&mysql));
return res;
}
m_res = mysql_use_result(&mysql);
m_row=mysql_fetch_row(m_res);
printf("%s\n",m_row[0]);
db_close();
}