Umstrukturierung von MySQL Funktionen in seperate Funktionen
-
Hallo zusammen,
nun Hintergrund der ganzen Geschichte ist ein Plugin welches ich für eine Engin schreibe. Diese benötigt in der DLL, die ich zu basteln versuche, die Spezifikation
"DLLFUNC Type Bezeichnung()"
als Funktion.Dieses Plugin soll eine MySQL Datenbank ansteuern können. Nach langem Suchen und versuchen bin ich auf ein kleines Script gestoßen, welches mir wenigstens in C++ zugriff auf eine MySQL Datenbank gestattet.
Jetzt allerdings habe ich das Problem, dass es nicht ganz so umzuschreiben ist, wie die Engin es benötigt.Es müssten die einzelnen MySQL Funktionen in den gesonderten DLLFUNC eingefügt werden, jedoch funktioniert das Script so nur am Stück.
Vor allem der MYSQL *Connect Pointer lässt sich nicht in eine Initialisierungsfunktion einfügen, ohne dass der rest nicht mehr funktioniert.
Hier einmal der Code:
#include "stdafx.h" #include "my_global.h" // Include this file first to avoid problems #include "mysql.h" // MySQL Include File #define SERVER "localhost" #define USER "root" #define PASSWORD "" #define DATABASE "cdcol" int main() { MYSQL *connect; // Create a pointer to the MySQL instance connect=mysql_init(NULL); // Initialise the instance connect=mysql_real_connect(connect,SERVER,USER,PASSWORD,DATABASE,0,NULL,0); /* Following if statements are unneeded too, but it's worth it to show on your first app, so that if your database is empty or the query didn't return anything it will at least let you know that the connection to the mysql server was established. */ if(connect){ printf("Connection Succeeded\n"); } else{ printf("Connection Failed!\n"); } MYSQL_RES *res_set; /* Create a pointer to recieve the return value.*/ MYSQL_ROW row; /* Assign variable for rows. */ mysql_query(connect,"SELECT * FROM cds"); /* Send a query to the database. */ unsigned int i = 0; /* Create a counter for the rows */ res_set = mysql_store_result(connect); /* Receive the result and store it in res_set */ my_ulonglong numrows = mysql_num_rows(res_set); /* Create the count to print all rows */ /* This while is to print all rows and not just the first row found, */ while ((row = mysql_fetch_row(res_set)) != NULL){ printf("%s\n",row[i] != NULL ? row[i] : "NULL"); /* Print the row data */ } mysql_close(connect); /* Close and shutdown */ return 0; }
Vielen Dank im Voraus
WaldnebelP.S.: Nach einer Woche harten Verzweifelns würde ich mich wirklich über Hilfe freuen
-
Waldnebel schrieb:
Es müssten die einzelnen MySQL Funktionen in den gesonderten DLLFUNC eingefügt werden, jedoch funktioniert das Script so nur am Stück.
Vor allem der MYSQL *Connect Pointer lässt sich nicht in eine Initialisierungsfunktion einfügen, ohne dass der rest nicht mehr funktioniert.
Du kannst den Beispiel-Code also nicht für deine Bedürfnisse anpassen, oder was?
Vielleicht kann dir jemand helfen, wenn du das Problem genauer beschreibst (mit dem Code, der nicht funktioniert).
-
Hat sich nun erledigt
Aber danke