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...
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...
Last edited by Kemi; 13th November 2015 at 16:08.
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);
}
Last edited by IzNoGoD; 13th November 2015 at 16:23.
"Does not work" is an error report for a bug between keyboard and chair.
All hail Artie Effem
Kemi (10th May 2017),kung foo man (13th November 2015)
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)
"Does not work" is an error report for a bug between keyboard and chair.
All hail Artie Effem
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.
timescale 0.01