Last change
on this file since 94ebbd9 was e3535b3, checked in by dportnoy <dmp1488@…>, 12 years ago |
Initial commit for server
|
-
Property mode
set to
100644
|
File size:
897 bytes
|
Line | |
---|
1 | #include "database.h"
|
---|
2 |
|
---|
3 | #include <string>
|
---|
4 | #include <mysql/mysql.h>
|
---|
5 |
|
---|
6 | using namespace std;
|
---|
7 |
|
---|
8 | Database::Database(string host, string username, string password, string database)
|
---|
9 | {
|
---|
10 | mysql_init(&(this->mysql));
|
---|
11 |
|
---|
12 | this->conn = mysql_real_connect(&(this->mysql),
|
---|
13 | host.c_str(), username.c_str(), password.c_str(), database.c_str(),
|
---|
14 | 0, 0, 0);
|
---|
15 |
|
---|
16 | if (this->conn == NULL) {
|
---|
17 | // throw an error
|
---|
18 | }
|
---|
19 | }
|
---|
20 |
|
---|
21 | Database::~Database()
|
---|
22 | {
|
---|
23 | mysql_close(conn);
|
---|
24 | }
|
---|
25 |
|
---|
26 | void Database::createUser(string username, string password)
|
---|
27 | {
|
---|
28 | MYSQL_RES *result;
|
---|
29 | MYSQL_ROW row;
|
---|
30 | int query_state;
|
---|
31 |
|
---|
32 | query_state = mysql_query(conn, (string()+"INSERT INTO users VALUES ("+username+","+password+")").c_str());
|
---|
33 |
|
---|
34 | if (query_state !=0) {
|
---|
35 | // throw an error
|
---|
36 | }
|
---|
37 |
|
---|
38 | mysql_free_result(result);
|
---|
39 | }
|
---|
40 |
|
---|
41 | string Database::getPassword(string username)
|
---|
42 | {
|
---|
43 | return "defaultPassword";
|
---|
44 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.