- Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexample.cpp
More file actions
Latest commit
executable file
·65 lines (50 loc) · 1.33 KB
/
Copy pathexample.cpp
File metadata and controls
executable file
·65 lines (50 loc) · 1.33 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include"mysqlwrapper.h"
// MYSQL TABLE EXAMPLE
// CREATE TABLE book
// (
// id INT(11) NOT NULL AUTO_INCREMENT,
// title VARCHAR(64),
// author_name VARCHAR(32),
// detail TEXT,
// PRIMARY KEY (id)
// );
intmain(int argc, char* argv[])
{
constchar *server = "localhost";
constchar *user = "root";
constchar *password = "password";
constchar *database = "myapp";
MySqlWrapper sql;
sql.init();
if(sql.connect(server, user, password, database) == false){
printf("error %s\n", sql.getError());
return0;
}
if( sql.query("DELETE FROM book;") == false){
printf("error %s\n", sql.getError());
return0;
}
sql.clear();
if( sql.query("INSERT INTO book (title, author_name) VALUES ('book_A', 'auth_A');") == false){
printf("error %s\n", sql.getError());
return0;
}
sql.clear();
if( sql.query("INSERT INTO book (title, author_name) VALUES ('book_B', 'auth_B');") == false){
printf("error %s\n", sql.getError());
return0;
}
sql.clear();
if( sql.query("SELECT * FROM book;") == false){
printf("error %s\n", sql.getError());
return0;
}
longlong nRows = sql.getRowCount();
MYSQL_ROW row;
while( (row = sql.getRow()) != NULL ){
printf("%s %s %s\n", row[0], row[1], row[2]);
}
sql.clear();
sql.close();
return0;
}