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
So how is that Database build? For example I call a database with the name "players".Code: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); }
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?

Reply With Quote