-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDb.cpp
More file actions
28 lines (25 loc) · 724 Bytes
/
Db.cpp
File metadata and controls
28 lines (25 loc) · 724 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include "Db.h"
Db::Db(Person *p) : person(p)
{
}
// insertData() - inserts data into DB
void Db::insertData()
{
QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
db.setHostName("127.0.0.1");
db.setPort(6994);
db.setDatabaseName("test");
db.setUserName("root");
db.setPassword("thisismysql");
bool ok = db.open();
if(ok)
{
QSqlQuery query;
QString querry = QString("INSERT into person values ('%1', '%2', '%3', '%4')")
.arg(person->getName()).arg(person->getPhoneNo())
.arg(person->getEmailId()).arg(person->getDeptCode());
if(query.exec(querry))
std::cout << "\nDone";
}
db.close();
}