本文介绍了Qt SQL准备失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试运行此Qt代码
I'm trying to run this Qt code
QString serverName = "localhost";
QString dbName = "zfserver";
QString userName = "root";
QString passWord = "123456";
QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
db.setConnectOptions();
db.setHostName(serverName);
db.setDatabaseName(dbName);
db.setUserName(userName);
db.setPassword(passWord);
if(db.open())
{
QSqlQuery query;
query.prepare("INSERT INTO account (name, email, password, type) "
"VALUES (:name, :email, :password, :type)");
query.bindValue(":name", "atef");
query.bindValue(":email", "[email protected]");
query.bindValue(":password", "123");
query.bindValue(":type", "2");
if (query.exec())
{
qDebug() << "OK";
} else {
qDebug() << "Error" << query.lastError().text();
}
db.close();
}
但是我遇到了这个错误
如果我更改了不带bindValue的查询,它将起作用.有办法解决吗?
If I change the query without the bindValue it works. Is there a way to solve this?
推荐答案
尝试重建SQL驱动程序.
Try to rebuild the SQL driver .
QMYSQL3
似乎很老.
这篇关于Qt SQL准备失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!