In case anyone is looking at setting up a game server with the intention of using MySQL as the data repository, after some effort I managed to cobble together the jigsaw.
You may not require all of the following, however it worked for me. Firstly install stuff like Apache, MySQL, PHP. I found a good guide for this here:
http://www.devarticles.com/c/a/Apache/Installing-PHP-under-Windows/2/
You may also wish to install PHPMyAdmin as its a reasonably good interface.
http://www.aota.net/PHP_and_MySQL/phpmyadmin.php4
And if you have problems with accessing MySQL via PHPMyAdmin once it installed you may wish to consider the following:
http://geekswithblogs.net/timh/archive/2005/10/31/58591.aspx
Once you\'ve managed to get the server running, you can access it via C++ using code along the lines of the following:
// Dark GDK - The Game Creators - www.thegamecreators.com
#include <DarkGDK.h>
#include <multisync.h>
#include <mysql.h>
// MYSQL
#define server \"localhost\"
#define username \"root\"
#define password \"root\"
#define database \"Ahoy\"
#define table \"player\"
MYSQL *conn;
// Multisync
#define MAX_CONNECTED 16
char MultiSyncServerName[] = \"MultiSync Basic Server for GDK v0.alpha\";
char serverip[] = \"127.0.0.1\";
char tempstr[256];
bool connected = false;
int connection = 0;
int connections = 0;
int playerleft = 0;
//
int player = 0;
int playerID[MAX_CONNECTED];
// prototypes
void showTables(MYSQL*);
void showContents(MYSQL*,const char*);
void DarkGDK(void)
{
dbSyncOn();
dbSyncRate(60);
dbPositionCamera(10, 10, -20);
// MYSQL
MYSQL *hnd=NULL; // mysql connection handle
const char *sinf=NULL; // mysql server information
hnd = mysql_init(NULL);
if (NULL == mysql_real_connect(hnd,server,username,password,database,0,NULL,0))
{
sprintf(tempstr,\"Problem encountered connecting to the %s database on %s.\\n\",database,server);
dbText(0, 12, tempstr);
}
else
{
sprintf(tempstr,\"Connected to the %s database on %s as user \'%s\'.\\n\",database,server,username);
sinf = mysql_get_server_info(hnd);
if (sinf != NULL)
{
sprintf(tempstr,\"Got server information: \'%s\'\\n\",sinf);
dbText(0, 12, tempstr);
showTables(hnd);
}
else
{
sprintf(tempstr,\"Failed to retrieve the server information string.\\n\");
dbText(0, 12, tempstr);
}
mysql_close(hnd);
}
//
//MultiSync
NetSetPort(23);
if (!NetHost(MAX_CONNECTED))
{
NetGetError(tempstr, 256);
MessageBox(NULL, tempstr, MultiSyncServerName, MB_ICONEXCLAMATION);
}
else MessageBox(NULL, \"Ready for connections.\",
MultiSyncServerName, MB_ICONINFORMATION);
while (LoopGDK())
{
connection = NetPlayerJoined();
if (connection != 0)
{
NetPutString(MultiSyncServerName);
NetSend(connection);
connections++;
//
player=player++;
playerID[player] = connection;
dbMakeObjectCube(playerID[player], 32);
//
}
playerleft = NetPlayerLeft();
if (playerleft)
{
connections--;
}
//
sprintf(tempstr, \"%i connected\", connections);
dbText(0, 400, tempstr);
sprintf(tempstr, \"playerID - %i\", playerID[1]);
dbText(0, 412, tempstr);
dbSync();
}
//
return;
}
// List Tables
void showTables(MYSQL *handle)
{
MYSQL_RES *result=NULL; // result of asking the database for a listing of its tables
MYSQL_ROW row; // one row from the result set
result = mysql_list_tables(handle,NULL);
row = mysql_fetch_row(result);
sprintf(tempstr,\"Tables found:\\n\\n\");
dbText(0, 36, tempstr);
int var_y=0;
while (row)
{
var_y++;
sprintf(tempstr,\"\\t%s\\n\",row[0]);
dbText(0, 36+(var_y*12), tempstr);
row = mysql_fetch_row(result);
}
mysql_free_result(result);
return;
}
The MySQL defined variables in the above code will need changing to reflect your MySQL database configuration. The above code includes some Multisync stuff as I\'m too lazy to edit it out.