PDA

View Full Version : mysql init



Ni3ls
16th August 2018, 12:38
Hi all,

I want to setup mysql

init()
{
//get your host, user, pass, db, port here
level.mysql = mysql_reuse_connection();
host = getcvar("mysql_host");
user = getcvar("mysql_user");
pass = getcvar("mysql_password");
db = getcvar("mysql_database");
if(!isDefined(level.mysql))
level.mysql = initMySQL(host, user, pass, db, 3306);
initAsyncMySQL(host, user, pass, db, 3306);
}

in the config I have (which is loaded)

set mysql_host "hostname"
set mysql_user "username"
set mysql_password "pw"
set mysql_database "dbname"

This aint working, I get a segmentation fault.
But when I directly write it in the initmysql function, it is working.

init()
{
//get your host, user, pass, db, port here
level.mysql = mysql_reuse_connection();
host = getcvar("mysql_host");
user = getcvar("mysql_user");
pass = getcvar("mysql_password");
db = getcvar("mysql_database");
if(!isDefined(level.mysql))
level.mysql = initMySQL(hostname, username, pw, dbname, 3306);
initAsyncMySQL(hostname, username, pw, dbname, 3306);
}
What could be the problem?

maxdamage99
16th August 2018, 13:03
initMySQL
initAsyncMySQL

what this? :D

Are you sure that the cvars are not null? (Yes, i know: libcod checks params, but look what you get there at the moment of call the function)

Ni3ls
16th August 2018, 13:45
those are functions from standard mysql script from here somewhere

Whiskas
16th August 2018, 14:06
Is it good idea to store those credentials in .cfg file?

Ni3ls
16th August 2018, 14:13
Is it good idea to store those credentials in .cfg file?

where else?

Whiskas
16th August 2018, 14:19
where else?

Directly in init function

Ni3ls
16th August 2018, 14:36
I thought it was more secure to write in a random cfg

IzNoGoD
16th August 2018, 15:45
Getting them from cvars works for me.

kung foo man
16th August 2018, 17:29
initMySQL
initAsyncMySQL

what this? :D



IzNoGoDs, high level of abstraction from C API for easier coding, once you got the pieces together:

https://killtube.org/showthread.php?1883-Asynchronous-mysql-queries&p=13719&viewfull=1#post13719
https://github.com/iznogod/OSJH/blob/master/OSJH/jh/mysql.gsc

My example test script kinda as raw as it gets, write-your-own-wrapper style, probably nice for testing:

https://github.com/kungfooman/cod2_std/blob/master/mysql_debugging.gsc

I don't know if anybody made changes to the MySQL C/GSC API aswell in newer libcod versions, which might cause problems. Which version are you using?

In a "perfect/nonlazy/paid" world, each breaking API change should force a new internal version to libcod's subcomponents like the MySQL system. So we could just add Mayor/Minor versions and quickly see if libcod/scripts are compatible.

IzNoGoD
16th August 2018, 19:19
https://github.com/iznogod/OSJH/blob/master/OSJH/jh/mysql.gsc

Feel free to use. Some example usages also shown in the related files.

serthy
16th August 2018, 21:29
I'll leave you here a link of an 2 year old project. I used mysql to store some logs of chat-commands, maybe some1 can use this https://github.com/nonsensation/CoD2-MySql-ClientCmd