A
für DevCPP gibt es auch neuerdings auch ein mysql beispiel1. Simpel gehalten:
/*
Name: MySQLClientTest (module)
Original Author: Dinesh V. R., dinesh@dvrsol.com
Editor: Kip Warner, "decrypted" into Vertigo syntax and prepared for dev
Date: 23/03/03 12:38
Description: Example to show usage of MySQL databases.
*/
// Includes...
#include <windows.h>
#include <mysql.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
// Database name...
char szDB[] = "evolution";
const int nMaxBufSize = 1024;
// Entry point...
int main(int argc, char *argv[])
{
// Variables...
MYSQL *myData;
MYSQL_RES *res;
MYSQL_FIELD *fd;
MYSQL_ROW row;
int i, j, k, l, x;
char aszFlds[25][25];
char szSQL[] = "SELECT * FROM b2users"; // assumed that there is table properties
// Try to select database and check for error...
if((myData = mysql_init((MYSQL*) 0)) &&
mysql_real_connect( myData, NULL, NULL, NULL, NULL, MYSQL_PORT, NULL, 0 ))
{
// Failed...
if(mysql_select_db(myData, szDB) < 0)
{
// Tell user what's going on, close database, then quit...
printf("Can't select the %s database!\n", szDB);
mysql_close(myData);
getch();
return 2;
}
}
// Failed to connect...
else
{
// Tell user what's going on, close database, then quit...
printf("Can't connect to the mysql server on port %d!\n", MYSQL_PORT);
mysql_close(myData);
getch();
return 1;
}
// Query database with "SELECT * FROM PROPERTIES" command...
if(mysql_query(myData, szSQL) == 0)
{
// I have no idea what he's doing here...
res = mysql_store_result(myData);
i = (int) mysql_num_rows(res);
l = 1;
// Display query result...
printf("Query: %s\nNumber of records found: %d\n", szSQL, i);
// Get the field-specific characteristics here....
for(x = 0; fd = mysql_fetch_field(res); x++)
strcpy(aszFlds[x], fd->name);
// I have no idea what he is doing here either...
while(row = mysql_fetch_row(res))
{
// Wtf...
j = mysql_num_fields(res);
printf( "Record #%d:-\n", l++);
for(k = 0 ; k < j ; k++)
printf( " Fld #%d (%s): %s\n", k + 1, aszFlds[k],
(((row[k]==NULL)||(!strlen(row[k]))) ? "NULL" : row[k]));
puts("==============================\n");
}
// Free the result...
mysql_free_result(res);
}
// Failed to query database...
else
printf("Couldn't execute %s on the server !\n", szSQL);
// Close connection to database...
mysql_close(myData);
// Wait for key, then terminate...
getch();
return 0;
}