PDA

View Full Version : Setup mysql + cod2



Ni3ls
1st March 2016, 18:13
Hi all,

I used the save the stats on a loginname with scriptdata, but I want to change to the use of mysql. But I dont know much about it.
How to start? Do I have to setup a database first (Like for B3)?

Then Kung posted this script

mysql_test()
{
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))
{
printfline("mysql not defined!");
return;
}

printfline("mysql=" + ("2"+2) + "\n");

ret = mysql_real_connect(mysql, host, user, pass, db, port);
if (!ret)
{
printfline("errno="+mysql_errno(mysql) + " error=''"+mysql_error(mysql) + "''\n");
mysql_close(mysql);
return 0;
}

printfline("affected_rows="+mysql_affected_rows(mysql)+"\n");



name = "fo\"0'z0`r"; // all user-input is evil!
name = mysql_real_escape_string(mysql, name); // so escape it :)

theQuery = "SELECT * FROM players";
theQuery = "SELECT \""+name+"\" as first,2 as second,3 as third UNION SELECT 11,22,33";

printfline(theQuery);

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

result = mysql_store_result(mysql);

printfline("num_rows="+mysql_num_rows(result) + " 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;
printfline("field-name=" + result_name+"\n");
}

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

mysql_free_result(result);

mysql_close(mysql);

}

So how is that Database build? For example I call a database with the name "players".
The first thing I want to see is the loginname, followed by password and then the kills.
How can I save it like that?
And how can I load it?
And what if the name already exist?

kung foo man
1st March 2016, 19:33
The query to create the table is in cod2_std/persistence.gsc: https://github.com/kungfooman/cod2_std/blob/master/persistence.gsc

Connect with HeidiSQL to your MySQL server and just execute the CREATE TABLE query etc. to get a feel what those queries in persistence.gsc do: http://www.heidisql.com/

IzNoGoD
2nd March 2016, 04:42
http://killtube.org/showthread.php?1883-Asynchronous-mysql-queries&p=13719&viewfull=1#post13719