Mysql Problem
by Christian Weber · in Torque Game Engine · 08/23/2003 (4:19 pm) · 16 replies
Hi,
I have a little Problem connecting to a mysql database. Everything works just fine if I want to connect to a ip, but i only have a url of the mysql database where everything will be stored. Its something like "dbXXX.puretec.com" I cant ping the name so i cant get the ip. Any ideas how i could connect to this database?
thx,
Chris
I have a little Problem connecting to a mysql database. Everything works just fine if I want to connect to a ip, but i only have a url of the mysql database where everything will be stored. Its something like "dbXXX.puretec.com" I cant ping the name so i cant get the ip. Any ideas how i could connect to this database?
thx,
Chris
About the author
#2
thx.
08/23/2003 (7:27 pm)
Ok fixed it, now i have a problem with a simple update script, but i dont get it to work. Quote:
function UpdateGameScore(%client, %name, %score);
{
%mysqltest.Connect();
%mysqltest.Query ("SELECT %name FROM account");
%result= %mysqltest.StoreResult();
%allkills = %mysqltest.GetRowCell (%result, "kills");
%kills = %allkills+score;
%mysqltest.Query ("UPDATE account SET kills = %kills");
%mysqltest.FreeResult (%result);
%mysqltest.Close();
messageClient(%client,
'MsgClientJoin', '\c3Account updated.',
%client.name,
%client,
%client.sendGuid,
%client.score,
%client.isAiControlled(),
%client.isAdmin,
%client.isSuperAdmin);
}
thx.
#4
1. Shouldn't it read %kills = %allkills + %score; (forgot the %sign in front of score)?
2. %mysqltest.Query ("UPDATE account SET kills = %kills WHERE name = %name");
3. %client.isAiControlled() <- is this a function???
08/24/2003 (4:31 am)
I can' test it, but here is what I think could be wrong:1. Shouldn't it read %kills = %allkills + %score; (forgot the %sign in front of score)?
2. %mysqltest.Query ("UPDATE account SET kills = %kills WHERE name = %name");
3. %client.isAiControlled() <- is this a function???
#5
Thx for your help.
08/24/2003 (5:46 am)
Ok thx. 1 and 2 were correct an yes 3 is a function i think. I dont get an error there. But I have still an error.Quote:
fps/server/scripts/game.cs Line: 145 - Syntax error.
>>> Advanced script error report. Line 289.
>>> Some error context, with ## on sides of error halt:
cycleGame();
}
function UpdateGameScore(%client, %name, %score);##
##
{
%mysqltest.Connect();
%mysqltest.Query ("SELECT %name FROM account");
>>> Error report complete.
Thx for your help.
#6
"function UpdateGameScore(%client, %name, %score);"
But if i call the function i get the following error
Thx
08/24/2003 (5:53 am)
Ok i found the mistake. *gives himself a headnut* I made a ";" after the function."function UpdateGameScore(%client, %name, %score);"
But if i call the function i get the following error
Quote:
MySQL ERROR: 'You have an error in your SQL syntax near '%name FROM account' at line 1'
MySQL ERROR: 'You have an error in your SQL syntax near '%name FROM account' at line 1'
MySQL: invalid result id: 0
MySQL ERROR: 'You have an error in your SQL syntax near '%kills WHERE name = %name' at line 1'
MySQL: invalid result id: 0
MySQL ERROR: 'You have an error in your SQL syntax near '%name FROM account' at line 1'
MySQL ERROR: 'You have an error in your SQL syntax near '%name FROM account' at line 1'
MySQL: invalid result id: 0
MySQL ERROR: 'You have an error in your SQL syntax near '%kills WHERE name = %name' at line 1'
MySQL: invalid result id: 0
Thx
#7
Look at:
what you want is something like
And, like iko said, there is another error:
should be
Maybe you should pay more attention to what you are doing the next time... ;)
08/24/2003 (11:24 pm)
Well, besides all the other errors mentioned above, your select statement is wrong :PLook at:
%mysqltest.Query ("SELECT %name FROM account");which is totally wrong...you are searching for "%name" as a string, which doesnt return anything of course.... even worse, SQL uses the "%" sign, too, as a placeholder char so that you can write "fuzzy" queries like "SELECT * FROM ACCOUNTS WHERE NAME LIKE '%BLOOD%'";... so the statement above doesn't make any sense to mysql (or any other database)... :P
what you want is something like
%mysqltest.Query ("SELECT" SPC %name SPC "FROM account");
and
%mysqltest.Query ("UPDATE account SET kills =" SPC %kills);And, like iko said, there is another error:
%kills = %allkills+score;
should be
%kills = %allkills + %score;
Maybe you should pay more attention to what you are doing the next time... ;)
#8
This is the function:
and this is the error:
But thanks, maybe i should pay more attention yes. ;-)
08/25/2003 (3:57 am)
Thx but Im still getting those errors. This is the function:
Quote:
%updatescore.Connect();
%updatescore.Query ("SELECT" SPC %name SPC "FROM account");
%result= %updatescore.StoreResult();
%allkills = %updatescore.GetRowCell (%result, "kills");
%kills = %allkills + %score;
%updatescore.Query ("UPDATE account SET kills =" SPC %kills);
%updatescore.FreeResult (%result);
%updatescore.Close();
messageClient(%client,
'MsgClientJoin', '\c3Account updated.',
%client.name,
%client,
%client.sendGuid,
%client.score,
%client.isAiControlled,
%client.isAdmin,
%client.isSuperAdmin);
}
and this is the error:
Quote:
MySQL ERROR: 'You have an error in your SQL syntax near 'FROM account' at line 1'
MySQL ERROR: 'You have an error in your SQL syntax near 'FROM account' at line 1'
MySQL: invalid result id: 0
MySQL: invalid result id: 0
But thanks, maybe i should pay more attention yes. ;-)
#9
It shouldnt be
It cant hurt using a tool like MYSQLFront or any other frontend... and then testing your queries before you try them from Torque...
08/25/2003 (5:43 am)
Err, I only saw the syntax errors, but there is a logical error in your select statement...It shouldnt be
"SELECT beffy FROM account"what you want is something like
"SELECT * FROM account WHERE username LIKE 'beffy'"or, in your function:
%updatescore.Query ("SELECT * FROM account WHERE username like '" @ %name @ "'");(assuming your column is named "username")It cant hurt using a tool like MYSQLFront or any other frontend... and then testing your queries before you try them from Torque...
#10
Im getting this error...
I will test it with mysqlfront
thx
08/25/2003 (7:00 am)
There has to be a Problem with [´"@%name@"´");]Im getting this error...
Quote:
MySQL ERROR: 'You have an error in your SQL syntax near '´´' at line 1'
MySQL ERROR: 'You have an error in your SQL syntax near '´´' at line 1'
MySQL: invalid result id: 0
MySQL: invalid result id: 0
I will test it with mysqlfront
thx
#11
The ´beffy´ part is supposed to be a special character something like (') so just change that part to be like: 'beffy'.
Try checking the MySQL manual. it's already inside the tar.gz in its release.
The syntax for a SELECT query should be like:
"SELECT [name of column, if any column, use *] FROM [name of table] WHERE [conditional selection for extensive uses]"
Hope that helps,
[g]
08/25/2003 (7:19 am)
Chris,The ´beffy´ part is supposed to be a special character something like (') so just change that part to be like: 'beffy'.
Try checking the MySQL manual. it's already inside the tar.gz in its release.
The syntax for a SELECT query should be like:
"SELECT [name of column, if any column, use *] FROM [name of table] WHERE [conditional selection for extensive uses]"
Hope that helps,
[g]
#12
So it should read like this:
08/25/2003 (7:24 am)
Yeah, Guntur is right, the GG forums are replacing the ' quotes with ´.So it should read like this:
%updatescore.Query ("SELECT * FROM account WHERE username like '" @ %name @ "'");(Hope this comes through correctly... :P)
#13
And now I have another problem... ya ya i know. ;-) Sometimes it works and sometimes im getting a critical error so the app has to be closed. Dont know why. Its always the same situation so it happens randomly.
thx for your help.
Chris
08/25/2003 (8:25 am)
Well, i dont get errors anymore. Here is the script:Quote:
%updatescore.Connect();
%updatescore.Query ("SELECT * FROM account WHERE username = '" @ %name @ "'");
%result= %updatescore.StoreResult();
%allkills = %updatescore.GetRowCell (%result, "kills");
%kills = %allkills + %score;
%updatescore.Query ("UPDATE account SET kills = '" @ %kills @ "' WHERE username = '"@%name@"'");
%updatescore.FreeResult (%result);
%updatescore.Close();
messageClient(%client,
'MsgClientJoin', '\c3Account updated.',
%client.name,
%client,
%client.sendGuid,
%client.score,
%client.isAiControlled,
%client.isAdmin,
%client.isSuperAdmin);
And now I have another problem... ya ya i know. ;-) Sometimes it works and sometimes im getting a critical error so the app has to be closed. Dont know why. Its always the same situation so it happens randomly.
thx for your help.
Chris
#14
as for your app crashing, i have no idea. ! ;/
08/25/2003 (11:20 am)
Also, there still is www.mysql.com/! ;)as for your app crashing, i have no idea. ! ;/
#15
08/25/2003 (11:24 am)
Ok thx, the script works just fine, but the crashing is a bit strange.
#16
Chris
08/26/2003 (5:43 am)
I made all the queries in a php script, everything worked. maybe i should transfer everything through a script with the php file. just like in the Persistant Character Server tutorial of Daniel Neilsen. should work i think. thanks for your help.Chris
Associate Ben Garney