C++新手现遇棘手问题,向各位前辈求解.
wfyq 2003-10-20 11:59:48 #include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<mysql/mysql.h>
#include<string>
using namespace std;
int main()
{
MYSQL mysql;
MYSQL_RES * result;
MYSQL_ROW row;
string input(getenv("QUERY_STRING"));
string phone;
char *display;
char *p;
cout<<"Content-type:text/html"<<endl<<endl;
cout <<"<html>";
string temp=input;
p=strtok(temp.begin(),"&"); //编译时这一行有错,但我不知如何该.
phone.assign(p);
phone.erase(0,phone.find("=")+1);
mysql_init(&mysql);
mysql_real_connect(&mysql,NULL,"root",NULL,"test",0,0,0);
char query[255];
sprintf(query,"select * from test where='%s'", phone.c_str());
mysql_query(&mysql,query);
result=mysql_store_result(&mysql);
if(mysql_num_rows(result)==0)
{
display=new char[25];
strcpy(display,"phone not fonud!!Retry!!");
cout<<display<<endl;
exit(1);
}
while(row=mysql_fetch_row(result))
{
cout<<"<br>";
cout<<row[0]<<":"<<row[1]<<":"<<row[2]<<":";
cout<<row[3];
cout<<"</br>";
}
cout<<"</html>";
mysql_close(&mysql);
return 0;
}