-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathdatabase.cc
executable file
·92 lines (76 loc) · 2.84 KB
/
database.cc
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/*
* ===================================================================
*
* Filename: database.cc
*
* Description: Definition of MySQL Class for accessing database
*
* Created: Friday 22 February 2013 02:07:49 IST
* Compiler: gcc
*
* Author: Mandeep Kaur, meghasimak@gmail.com
* License: GNU General Public License
* Copyright: Copyright (c) 2013, Great Developers
*
* ===================================================================
*/
/**-------------------------------------------------------------------
* Include mysql.h file local header file(declaration of class)
*------------------------------------------------------------------*/
#include "database.h"
/**
*--------------------------------------------------------------------
* Class: MySQL
* Method: MySQL :: MySQL()
* Description: Constructor to initialize database conectivity
*--------------------------------------------------------------------
*/
MySQL :: MySQL()
{
connect = mysql_init(NULL);
if ( !connect )
{
cout << "MySQL Initialization Failed";
}
connect = mysql_real_connect(connect, SERVER, USER, PASSWORD, DATABASE, 0,NULL,0);
if ( connect )
{
cout << "Connection Succeeded\n";
}
else
{
cout << "Connection Failed\n";
}
}
/**
*--------------------------------------------------------------------
* Class: MySQL
* Method: MySQL :: ShowTables()
* Description: Show tables in database
*--------------------------------------------------------------------
*/
void MySQL :: ShowTables()
{
/** Add MySQL Query */
mysql_query (connect,"show tables");
i = 0;
res_set = mysql_store_result(connect);
unsigned int numrows = mysql_num_rows(res_set);
cout << " Tables in " << DATABASE << " database " << endl;
while (((row=mysql_fetch_row(res_set)) != NULL))
{
cout << row[i] << endl;
}
}
/**
*--------------------------------------------------------------------
* Class: MySQL
* Method: MySQL :: ~MySQL()
* Description: Destructor of MySQL class for closing mysql
* connection
*--------------------------------------------------------------------
*/
MySQL :: ~MySQL()
{
mysql_close (connect);
}