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", "asfasf@gfasga.com");
query.bindValue(":password", "123");
query.bindValue(":type", "2");
if (query.exec())
{
qDebug() << "OK";
} else {
qDebug() << "Error" << query.lastError().text();
}
db.close();
}
But I'm getting this error
Error "Using unsupported buffer type: 1701601889 (parameter: 1) QMYSQL3: Unable to bind value"
If I change the query without the bindValue it works. Is there a way to solve this?
Try to rebuild the SQL driver .
QMYSQL3
seems to be old.
来源:https://stackoverflow.com/questions/23147057/qt-sql-prepare-fails