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如何使用cpp程序將值插入數據庫(mySql)?
你應該添加一些錯誤檢查,如檢查是否'mysql_init'或'mysql_real_connect'沒有按」 t返回一個空指針。 –
插入不指定'userdetails'表的列名,在某些情況下這可能是個問題。檢查'mysql_query'是否報告錯誤並打印出來。 – karastojko