Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!
Werbeanzeige
C-/C++-Quelltext |
|
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 |
#include <windows.h> #include <mysql.h> #include "stdafx.h" #include <iostream> using namespace std; int main() { MYSQL *Connection; // MySQL Handle MYSQL_RES *Ergebnis; // Ergebnis einer Abfrage TCHAR Abfrage[10000]; // SQL Befehle MYSQL_ROW Zeile; // Ergebniszeile int Anz; // Anzahl der Zeilen int i; Connection = mysql_init(NULL); // Verbindung zum MySQL Server aufbauen if(mysql_real_connect( Connection, // MySQL Handle "localhost", // Host Name "root", // User "", // Passwort "test", // Datenbank "3306", // Port (Standard: 3306) NULL, // Socket (Standard: NULL) 0) == NULL) { cout << "Fehler! Es konnte keine Verbindung zur Datenbank hergestellt werden!" << endl; } else { cout << "Die Verbindung zur Datenbank wurde hergestellt!" << endl; } mysql_close(Connection); return 0; } |
Quellcode |
|
1 2 3 4 5 6 7 8 9 10 |
error C2065: 'MYSQL': nichtdeklarierter Bezeichner error C2065: 'Connection': nichtdeklarierter Bezeichner error C2065: 'MYSQL_RES': nichtdeklarierter Bezeichner error C2065: 'Ergebnis': nichtdeklarierter Bezeichner error C2065: 'MYSQL_ROW': nichtdeklarierter Bezeichner error C2146: Syntaxfehler: Fehlendes ';' vor Bezeichner 'Zeile' error C2065: 'Zeile': nichtdeklarierter Bezeichner error C3861: "mysql_init": Bezeichner wurde nicht gefunden. error C3861: "mysql_real_connect": Bezeichner wurde nicht gefunden. error C3861: "mysql_close": Bezeichner wurde nicht gefunden. |
Zitat von »"Deviloper"«
Und der meldet nicht, dass der den Header mysql.h nicht finden kann? da sind die FUnktionen und Strukturen nähmlich definiert ...
C-/C++-Quelltext |
|
1 |
#include <mysql.h> |
Zitat von »"David_pb"«
Wo liegt denn der Header mysql.h?
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
typedef struct st_mysql { NET net; /* Communication parameters */ gptr connector_fd; /* ConnectorFd for SSL */ char *host,*user,*passwd,*unix_socket,*server_version,*host_info, *info,*db; unsigned int port,client_flag,server_capabilities; unsigned int protocol_version; unsigned int field_count; unsigned int server_status; unsigned long thread_id; /* Id for connection in server */ my_ulonglong affected_rows; my_ulonglong insert_id; /* id if insert on table with NEXTNR */ my_ulonglong extra_info; /* Used by mysqlshow */ unsigned long packet_length; enum mysql_status status; MYSQL_FIELD *fields; MEM_ROOT field_alloc; my_bool free_me; /* If free in mysql_close */ my_bool reconnect; /* set to 1 if automatic reconnect */ struct st_mysql_options options; char scramble_buff[9]; struct charset_info_st *charset; unsigned int server_language; } MYSQL; |
C-/C++-Quelltext |
|
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 |
typedef struct st_mysql { NET net; /* Communication parameters */ gptr connector_fd; /* ConnectorFd for SSL */ char *host,*user,*passwd,*unix_socket,*server_version,*host_info,*info; char *db; struct charset_info_st *charset; MYSQL_FIELD *fields; MEM_ROOT field_alloc; my_ulonglong affected_rows; my_ulonglong insert_id; /* id if insert on table with NEXTNR */ my_ulonglong extra_info; /* Not used */ unsigned long thread_id; /* Id for connection in server */ unsigned long packet_length; unsigned int port; unsigned long client_flag,server_capabilities; unsigned int protocol_version; unsigned int field_count; unsigned int server_status; unsigned int server_language; unsigned int warning_count; struct st_mysql_options options; enum mysql_status status; my_bool free_me; /* If free in mysql_close */ my_bool reconnect; /* set to 1 if automatic reconnect */ /* session-wide random string */ char scramble[SCRAMBLE_LENGTH+1]; /* Set if this is the original connection, not a master or a slave we have added though mysql_rpl_probe() or mysql_set_master()/ mysql_add_slave() */ my_bool rpl_pivot; /* Pointers to the master, and the next slave connections, points to itself if lone connection. */ struct st_mysql* master, *next_slave; struct st_mysql* last_used_slave; /* needed for round-robin slave pick */ /* needed for send/read/store/use result to work correctly with replication */ struct st_mysql* last_used_con; LIST *stmts; /* list of all statements */ const struct st_mysql_methods *methods; void *thd; /* Points to boolean flag in MYSQL_RES or MYSQL_STMT. We set this flag from mysql_stmt_close if close had to cancel result set of this object. */ my_bool *unbuffered_fetch_owner; #if defined(EMBEDDED_LIBRARY) || defined(EMBEDDED_LIBRARY_COMPATIBLE) || MYSQL_VERSION_ID >= 50100 /* needed for embedded server - no net buffer to store the 'info' */ char *info_buffer; #endif } MYSQL; |
Zitat von »"David_pb"«
Naja, is ja egal! Auf jedenfall wird ganz unten MYSQL deklariert!
Achja: mysql++ sieht im Bezug auf C++ irgendwie viel interessanter aus!
Zitat von »"David_pb"«
So wie ich das sehe ist eher die Verwendung der C API für mysql unnötig kompliziert. Ich finde das C++ Design von mysql++ viel besser. Aber es gibt ja auch noch Leute die schlagen sich lieber mit C-Strings rum statt eine gescheite Stringbibliothek zu verwenden, oder?
C-/C++-Quelltext |
|
1 2 3 4 |
#include "stdafx.h" #include <iostream> #include <winsock2.h> #include <mysql.h> |
Werbeanzeige