【发布时间】:2016-11-23 08:06:32
【问题描述】:
void SignUp()
{
MYSQL* conn;
MYSQL_ROW row;
MYSQL_RES* res;
int nQueryState = 0;
int nId = 0;
char szName[45];
char szPassWord[45];
char szQuestion[45];
char szPhone[45];
cout<<"Enter the Id";
cin>>nId;
cout<<"Enter the Name";
cin>>szName;
cout<<"Enter the Password";
cin>>szPassWord;
cout<<"Enter the Question";
cin>>szQuestion;
cout<<"Enter the Phone";
cin>>szPhone;
conn = mysql_init(0);
conn =mysql_real_connect(conn,"localhost","root","12356","hari",0,NULL,0);
nQueryState = mysql_query(conn,"insert into userdetails values(nId,szName,szPassword,szQuestion,szPhone)");
if(0!=nQueryState)
{
cout<<"\n\nConnection not Established";
}
}
我想在名为 userdetails 的表中输入详细信息。它给了我一个输出,使得连接没有建立。请通过它并帮助我。我正在使用代码块 ide 和 mySql5.1
【问题讨论】:
-
您应该添加一些错误检查,例如检查
mysql_init或mysql_real_connect是否不返回空指针。 -
Insert 没有指定
userdetails表的列名,这在某些情况下可能是个问题。检查mysql_query是否报错并打印。