Can anyone point me in the right direction to connecting to MySQL then reading tables, columns and rows?
Already got MySQL setup with a database, example tables, columns and rows...
http://puu.sh/ldppj/c8e35880a8.png
Printable View
Can anyone point me in the right direction to connecting to MySQL then reading tables, columns and rows?
Already got MySQL setup with a database, example tables, columns and rows...
http://puu.sh/ldppj/c8e35880a8.png
I'm using this:
and this as helper:PHP Code:
level.mysql = mysql_reuse_connection();
if(!isdefined(level.mysql))
{
make_global_mysql(host, user, pass, db, port);
}
level.mysql_wrapper = ::mysql_wrapper;
Then I can just:PHP Code:
mysql_wrapper(query, saveResults)
{
if(!isDefined(saveResults))
saveResults = false;
mysql = level.mysql;
if(!isDefined(mysql))
return undefined;
if(getcvarint("show_mysql") == 1)
printf("mysql_query:" + query + "\n");
result = mysql_query(mysql, query);
resettimeout();
if(result)
return undefined;
if(saveResults)
return mysql_store_result(mysql);
return undefined;
}
make_global_mysql(host, user, pass, db, port)
{
mysql = mysql_init();
ret = mysql_real_connect(mysql, host, user, pass, db, port);
if(!ret)
{
printf("errno=" + mysql_errno(mysql) + " error= " + mysql_error(mysql) + "\n");
mysql_close(mysql);
return;
}
level.mysql = mysql;
}
stripstring(string)
{
return mysql_real_escape_string(level.mysql, string);
}
PHP Code:
result = [[level.mysql_wrapper]]("SELECT mapid FROM mapids WHERE mapname = '" + stripstring(mapname) + "'", true);
if(isdefined(result))
{
if(mysql_num_rows(result))
{
row = mysql_fetch_row(result);
level.mapid = int(row[0]);
}
mysql_free_result(result);
}
Follow-up:
1) test your queries
2) debug your queries
3) never trust anything the user can input, always escape it properly
4) always mysql_free_result(result) if result is defined
5) never free_result twice on the same result.
6) mysql will add laggs when your queries take longer than 0.05 seconds, use async mysql then (see some other thread)
Well, either libcod:
As example you can use this: https://github.com/kungfooman/cod2_s...bugging.gsc#L4
Or some primitive "communication" via the log files/rcon, as B3 does it.