前提:安装mysql 和mysql++、mysql++-devel
程序:#include
#include "mysql++.h"
#include
using namespace mysqlpp;
using namespace std;
int main()
{ char usrstr[30];
bool userexist=false;
cout<
cin>>usrstr;
//建立连接
mysqlpp::Connection con(false);
if(con.connect("test","localhost","root",""))
// test is db name ,localhost is server host name
{
cout<
mysqlpp::Query query=con.query("select username from userlist");
mysqlpp::StoreQueryResult res=query.store();
for (int i=0;i
{
if (strcmp(usrstr,res[i][0])==0)
userexist=true;
}
if (userexist)
cout<
}
}
编译连接:g+&#