PDA

View Full Version : cod2 download data from mysql



malyczolg
15th February 2015, 16:05
hello i try edit script for downloading data from mysql.
when i trying download player stats [ rank etc...], script download another table.



dane_gracza()
{
host = getcvar("mysql_host");
user = getcvar("mysql_user");
pass = getcvar("mysql_pass");
db = getcvar("mysql_db");
port = getcvarint("mysql_port");

mysql = mysql_init();

if ( ! isDefined(mysql))
{
iprintln("^1mysql not defined!");
return;
}

ret = mysql_real_connect(mysql, host, user, pass, db, port);
if (!ret)
{
iprintln("^1errno="+mysql_errno(mysql) + "^3 error=''"+mysql_error(mysql) + "''\n");
mysql_close(mysql);
return 0;
}
theQuery = "SELECT * FROM cod2_users WHERE username = 'czolg'";

iprintln("^1"+theQuery);

ret = mysql_query(mysql, theQuery);
if (ret != 0)
{
iprintln("^1errno="+mysql_errno(mysql) + "^7 error=''"+mysql_error(mysql) + "''\n");
mysql_close(mysql);
return 0;
}

result = mysql_store_result(mysql);

iprintln("^3num_rows="+mysql_num_rows(result) + "^9 num_fields="+mysql_num_fields(result)+"\n");

mysql_field_seek(result, 0);
while (1)
{
result_name = mysql_fetch_field(result);
if (!isString(result_name))
break;

iprintln("^4field-name=" + result_name+"\n");
}

while (1)
{
row = mysql_fetch_row(result);
if (!isDefined(row))
{
//std\io::print("row == undefined\n");
break;
}
output = "";
for (i=0; i<row.size; i++)
output += row[i] + " ";
std\io::print(output+"\n");
}

mysql_free_result(result);

mysql_close(mysql);
}

842844

kung foo man
15th February 2015, 16:44
Replace


std\io::print(output+"\n");

with


printf(output+"\n");

And replace your old std-files with these: https://github.com/kungfooman/cod2_std

Mitch
15th February 2015, 17:00
printf(output+"\n");

And replace your old std-files with these: https://github.com/kungfooman/cod2_std

Or use printfline (it automatically adds a \n).

malyczolg
15th February 2015, 19:45
work , thanks guys :)