Hallo,
Ben op het moment bezig met een mySQL class met de mysql functies daarin (C API)
Nu krijg ik de volgende error's:
Als ik de functie beschrijvingen op mysql.com lees zie ik dat mysql_store_result het type MYSQL_RES (struct) terug geeft en ik heb in de class de variabel 'myRes' als MYSQL_RES type gededefinieerd. Nu snap ik niet waarom ik niet met = operator mag verwijzen naar de lege variabel myRes die hetzelfde type is.
Op en aanmerkingen over de code zijn ook welkom
Ben op het moment bezig met een mySQL class met de mysql functies daarin (C API)
C++:
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
93
94
95
96
97
98
99
100
| #include <iostream> #include <windows.h> #include <MySQL\mysql.h> using namespace std; class Database { public: MYSQL myIns; MYSQL_RES myRes; MYSQL_FIELD myFld; MYSQL_ROW myRow; void init(); void connect(const char *hostname, const char *username, const char *password, unsigned int port); void selectdb(const char *database); void query(const char *query); void fetch(); Database(); ~Database(); }; Database::Database() { // } Database::~Database() { // } void Database::init() { if(mysql_init(&myIns) == NULL) { cout << "Could not initialize MySQL" << endl; mysql_close(&myIns); } } void Database::connect(const char *hostname, const char *username, const char *password, unsigned int port) { if(mysql_real_connect(&myIns,hostname,username,password,NULL,port,NULL,0) == NULL) { cout << "Could not connect with the database" << endl; mysql_close(&myIns); } } void Database::selectdb(const char *database) { if(mysql_select_db(&myIns,database) != 0) { cout << "Could not select database \'" << database << "\'" << endl; mysql_close(&myIns); } } void Database::query(const char *query) { if(mysql_query(&myIns,query) != 0) { cout << "Could not execute the query" << endl; mysql_close(&myIns); } myRes = mysql_store_result(&myIns); if(myRes == NULL) { cout << "Could not result the query" << endl; mysql_free_result(&myRes); mysql_close(&myIns); } } void Database::fetch() { unsigned long numRow; numRow = mysql_num_rows(&myRes); cout << "Found " << numRow << " records" << endl; mysql_free_result(&myRes); mysql_close(&myIns); } int main() { Database *SQL = new Database; SQL->init(); SQL->connect("localhost","root","",3306); SQL->selectdb("simplycms"); SQL->query("SELECT * FROM users;"); SQL->fetch(); system("PAUSE"); delete SQL; return 0; } |
Nu krijg ik de volgende error's:
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
| Compiler: Default compiler Building Makefile: "C:\Documents and Settings\Av3ng3r\Bureaublad\cpp\mySQL connector\Makefile.win" Executing make... make.exe -f "C:\Documents and Settings\Av3ng3r\Bureaublad\cpp\mySQL connector\Makefile.win" all g++.exe -c main.cpp -o main.o -I"C:/Dev-Cpp/include/c++/3.3.1" -I"C:/Dev-Cpp/include/c++/3.3.1/mingw32" -I"C:/Dev-Cpp/include/c++/3.3.1/backward" -I"C:/Dev-Cpp/lib/gcc-lib/mingw32/3.3.1/include" -I"C:/Dev-Cpp/include" -Wall main.cpp: In member function `void Database::query(const char*)': main.cpp:61: error: no match for 'operator=' in 'this->Database::myRes = mysql_store_result(MYSQL*)(this)' C:/Dev-Cpp/include/MySQL/mysql.h:208: error: candidates are: st_mysql_res& st_mysql_res::operator=(const st_mysql_res&) main.cpp:63: error: no match for 'operator==' in 'this->Database::myRes == 0' C:/Dev-Cpp/include/objbase.h:80: error: candidates are: BOOL operator==(const GUID&, const GUID&) main.cpp:100:2: warning: no newline at end of file make.exe: *** [main.o] Error 1 Execution terminated |
Als ik de functie beschrijvingen op mysql.com lees zie ik dat mysql_store_result het type MYSQL_RES (struct) terug geeft en ik heb in de class de variabel 'myRes' als MYSQL_RES type gededefinieerd. Nu snap ik niet waarom ik niet met = operator mag verwijzen naar de lege variabel myRes die hetzelfde type is.
Op en aanmerkingen over de code zijn ook welkom
[ Voor 9% gewijzigd door Av3ng3rtje op 20-02-2005 12:58 ]