MYSQL DON'T WORK
#1

IT'S CORRECT CODE?

Function OnAccountRegister isn't call
Reply
#2

Seems ok but you can increase array size if query[300];
What's the problem?
Reply
#3

It doesn't insert to data base
Reply
#4

Bump
Reply
#5

The Code seems ok to me, enable MySQL logging by putting 'mysql_log(LOG_ALL);' in OnGameModeInit before you connect to the db then try running the query and check MySQL log file in server directory it will show you what is the error. Make sure that the MySQL server is up and running.
Form your code I would like to give you some tips :
  • You are using `` around field names like `pCash` but it isn't mandatory to use `` around field names unless they are a MySQL keyword for example some people use 'char' as a field name which is also a MySQL keyword therefore you have to put `` around char in the query for it to work but i don't see such keyword in your query so you can avoid using ``. Thus it will help to reduce query size.
  • I see you insert values such as cash,admin,position...etc as 0/0.0. You can simply assign default values to them and then you can remove them from Insert query they will be automatically set to 0 when you insert a new account and thus making your query size a lot smaller. To modify column and add default value you can simply run queries like this :
    PHP код:
    ALTER TABLE playeraccounts MODIFY COLUMN pCash INT(11NOT NULL DEFAULT 0
Reply
#6

Please example to me
This is error log
Код:
[14:56:52] [DEBUG] mysql_connect - host: "localhost", user: "root", database: "server_database", password: "****", port: 3306, autoreconnect: true
[14:56:52] [DEBUG] CMySQLHandle::Create - creating new connection..
[14:56:52] [DEBUG] CMySQLHandle::CMySQLHandle - constructor called
[14:56:52] [DEBUG] CMySQLHandle::Create - connection created with ID = 1
[14:56:52] [DEBUG] CMySQLConnection::Connect - connection was successful
[14:56:52] [DEBUG] CMySQLConnection::Connect - auto-reconnect has been enabled
[14:56:52] [DEBUG] CMySQLConnection::Connect - connection was successful
[14:56:52] [DEBUG] CMySQLConnection::Connect - auto-reconnect has been enabled
[14:56:52] [DEBUG] mysql_errno - connection: 1
[14:57:17] [DEBUG] mysql_format - connection: 1, len: 128, format: "SELECT `pPassword`, `pID` FROM `playeraccounts` WHERE `Username` = '%e' LIMIT 1"
[14:57:17] [DEBUG] mysql_tquery - connection: 1, query: "SELECT `pPassword`, `pID` FROM `playeraccounts` WHERE `Username`", callback: "OnAccountCheck", format: "i"
[14:57:17] [DEBUG] CMySQLQuery::CMySQLQuery() - constructor called
[14:57:17] [DEBUG] mysql_tquery - scheduling query "SELECT `pPassword`, `pID` FROM `playeraccounts` WHERE `Username` = 'Daves' LIMIT 1"..
[14:57:17] [DEBUG] CMySQLQuery::Execute[OnAccountCheck(i)] - starting query execution
[14:57:17] [DEBUG] CMySQLQuery::Execute[OnAccountCheck(i)] - query was successful
[14:57:17] [DEBUG] CMySQLResult::CMySQLResult() - constructor called
[14:57:17] [DEBUG] CMySQLQuery::Execute[OnAccountCheck(i)] - data being passed to ProcessCallbacks()
[14:57:17] [DEBUG] Calling callback "OnAccountCheck"..
[14:57:17] [DEBUG] cache_get_data - connection: 1
[14:57:17] [DEBUG] CMySQLResult::~CMySQLResult() - deconstructor called
[14:57:17] [DEBUG] CMySQLQuery::~CMySQLQuery() - deconstructor called
[14:57:19] [DEBUG] mysql_format - connection: 1, len: 1000, format: ""INSERT INTO `playeraccounts` (`Username`, `pPassword`, `pCash`, `pMoney`, `pAdmin`, `pKills`, `pTeamFaction`, `pStaff`,`pSaveSk..."
[14:57:19] [DEBUG] mysql_tquery - connection: 1, query: ""INSERT INTO `playeraccounts` (`Username`, `pPassword`, `pCash`,", callback: "OnRegistered", format: "i"
[14:57:19] [DEBUG] CMySQLQuery::CMySQLQuery() - constructor called
[14:57:19] [DEBUG] mysql_tquery - scheduling query ""INSERT INTO `playeraccounts` (`Username`, `pPassword`, `pCash`, `pMoney`, `pAdmin`, `pKills`, `pTeamFaction`, `pStaff`,`pSaveSkin`, `pSelected`, `pCharater`, `pLoggedIn`, `pSpy`, `pFbi`, `pFaction`, `pQuit`,`pDeathRP`, `pSpawnPosX`, `pSpawnPosY`, `pSpawnPosZ`, `pSpawnSaved`, `pArmour`,`pHostAddress`, `pLastPlayed`, `pIP`, `pAmmo1`, `pAmmo2`, `pSpyRank`) VALUES ('Daves', '12345', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 'None', 0, '127.0.0.1', 0, 0, 'None')""..
[14:57:19] [DEBUG] CMySQLQuery::Execute[OnRegistered(i)] - starting query execution
[14:57:19] [ERROR] CMySQLQuery::Execute[OnRegistered(i)] - (error #1064) You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '"INSERT INTO `playeraccounts` (`Username`, `pPassword`, `pCash`, `pMoney`, `pAdm' at line 1
[14:57:19] [DEBUG] CMySQLQuery::Execute[OnRegistered(i)] - error will be triggered in OnQueryError
[14:57:19] [DEBUG] CMySQLQuery::Execute[OnRegistered(i)] - data being passed to ProcessCallbacks()
[14:57:19] [DEBUG] Calling callback "OnQueryError"..
[14:57:19] [DEBUG] CMySQLQuery::~CMySQLQuery() - deconstructor called
[14:57:22] [DEBUG] mysql_format - connection: 1, len: 1000, format: "UPDATE `playeraccounts` SET `pPassword`, `pIP`, `pAdmin`, `pKills`, `pMoney`,`pCash` ,`pTeamFaction`, `pStaff`, `pSaveSkin`, `pS..."
[14:57:22] [DEBUG] mysql_tquery - connection: 1, query: "UPDATE `playeraccounts` SET `pPassword`, `pIP`, `pAdmin`, `pKill", callback: "(null)", format: "(null)"
[14:57:22] [DEBUG] CMySQLQuery::CMySQLQuery() - constructor called
[14:57:22] [DEBUG] mysql_tquery - scheduling query "UPDATE `playeraccounts` SET `pPassword`, `pIP`, `pAdmin`, `pKills`, `pMoney`,`pCash` ,`pTeamFaction`, `pStaff`, `pSaveSkin`, `pSelected`, `pCharater`, `pLoggedIn`, `pSpy`,`pFbi`, `pFaction`, `pQuit`, `pDeathRP`, `pSpawnPosX`, `pSpawnPosY`, `pSpawnPosZ`, `pSpawnSaved`, `pArmour`,`pHostAddress`, `pLastPlayed`, `pAmmo1`, `pAmmo2` WHERE `ID`=80"..
[14:57:22] [DEBUG] CMySQLQuery::Execute[()] - starting query execution
[14:57:22] [ERROR] CMySQLQuery::Execute[()] - (error #1064) You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' `pIP`, `pAdmin`, `pKills`, `pMoney`,`pCash` ,`pTeamFaction`, `pStaff`, `pSaveSk' at line 1
[14:57:22] [DEBUG] CMySQLQuery::Execute[()] - error will be triggered in OnQueryError
[14:57:22] [DEBUG] CMySQLQuery::Execute[()] - data being passed to ProcessCallbacks()
[14:57:22] [DEBUG] Calling callback "OnQueryError"..
[14:57:22] [DEBUG] CMySQLQuery::~CMySQLQuery() - deconstructor called
Reply
#7

Ok so after checking length of query i found that it was 479 more than current query holding var size which is 300.
Either follow the things I told you in previous reply to reduce the query size(recommended) or increase the query variable size to 500(not recommended).
If you didn't understand what I told in the last reply then tell me i'll try to explain in more details.
Reply
#8

this ?

Reply
#9

You need to do new string[500], query[500]; to solve the problem
But as I told try to make query as small as possible, set the fields such as cash,admin..etc to 0 and then insert only name and IP. You don't need to insert all the fields at once!
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)