db.setDatabaseName("Справочник"); db.setUserName("root"); db.setPassword("1234567");
query.exec("insert into per values(102, 'Иван', 'Петров')");
QTextCodec::setCodecForTr(QTextCodec::codecForName("Windows-1251")); QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL"); db.setHostName("localhost"); db.setDatabaseName(QObject::tr("Reference")); db.setUserName("root"); db.setPassword("1234567");
QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8"));QTextCodec::setCodecForCString(QTextCodec::codecForName("UTF-8"));
query.exec("create table per(id int primary key, " "firstname varchar(20), lastname varchar(20));");
QString str,strF = "insert into table per(id, firstname, lastname)" "values(%1,'%2','%3');"; str=strF.arg("25") .arg("Show") .arg("Call"); if(!query.exec(str))
query.prepare("Insert into per(id, firstname, lastname) values(:id,:firstname,:lastname);"); query.bindValue(":id",25); query.bindValue(":firstname","qwer"); query.bindValue(":lastname","OLOL")