source: network-game/server/database.cpp@ cbc595d

Last change on this file since cbc595d was e3535b3, checked in by dportnoy <dmp1488@…>, 12 years ago

Initial commit for server

  • Property mode set to 100644
File size: 897 bytes
RevLine 
[e3535b3]1#include "database.h"
2
3#include <string>
4#include <mysql/mysql.h>
5
6using namespace std;
7
8Database::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
21Database::~Database()
22{
23 mysql_close(conn);
24}
25
26void 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
41string Database::getPassword(string username)
42{
43 return "defaultPassword";
44}
Note: See TracBrowser for help on using the repository browser.