-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathxconnection.cpp
More file actions
57 lines (46 loc) · 1015 Bytes
/
xconnection.cpp
File metadata and controls
57 lines (46 loc) · 1015 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
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
#include <string.h>
#include <string>
#include "xconnection.h"
using namespace std;
int xConnection::open(const char *hostName,const char *dbName,const char*userName, const char *password,int port)
{
if(m_conn != NULL){
return -1;
}
m_conn = mysql_init(NULL);
this->hostName = hostName;
this->dbName = dbName;
this->userName = userName;
this->password = password;
this->port = port;
mysql_real_connect(m_conn,hostName,userName,
password,dbName,port,NULL,0);
return 0;
}
void xConnection::close()
{
mysql_close(m_conn);
m_conn = NULL;
}
int xConnection::commit()
{
return mysql_commit(m_conn);
}
int xConnection::rollback()
{
char cmd[]="ROLLBACK";
if(!mysql_real_query(m_conn,cmd,strlen(cmd))){
return 0;
}
else{ //执行查询失败
return -1;
}
}
MYSQL *xConnection::getConnection()
{
return m_conn;
}
xStatement *xConnection::createStatement()
{
return NULL;
}