Hallo ihr,
mit mysql bin ich ja noch nie warm gewesen und ich komme mal wieder an einer Stelle nicht weiter. Zum ganzen drumherum, ich habe mir eine MySQL Klasse geschrieben und eine eigene Klasse welche die MySQL Statements speichert, damit ich diese an einem zentralen Ort habe und das Zeug nicht irgendwo wild im Code herumsteht. Das sieht dann zum Beispiel so aus:
MySQL_Statements_S.lua
MySQL = {}
MySQL.accountTable = "accounts"
MySQL.createPlayerTable = "CREATE TABLE IF NOT EXISTS `" .. MySQL.accountTable .. "` ( `account_id` BIGINT(20) NOT NULL AUTO_INCREMENT, `account_name` VARCHAR(255), `password` VARCHAR(255) NOT NULL, `skin_id` INT, `name` VARCHAR(255), `position` LONGTEXT, `rotation` LONGTEXT, PRIMARY KEY (`account_id`) ) COLLATE=`utf8_general_ci`;"
MySQL.getAllAccountData = "SELECT * FROM " .. MySQL.accountTable
MySQL.getAccountData = "SELECT * FROM " .. MySQL.accountTable .. " WHERE account_name=?"
MySQL.saveAccountData = "INSERT INTO " .. MySQL.accountTable .. " VALUES (?,?,?,?,?,?,?)"
MySQL.updateAccountData = "UPDATE " .. MySQL.accountTable .. " SET account_name=`?`, password=`?`, skin_id=`?`, playerName=`?`, position=`?`, rotation=`?` WHERE account_id=?"
Alles anzeigen
MySQL_Manager_S.lua
.
.
.
function MySQLManager_S:query(statement, ...)
if (self.dbConnection) then
local finalString = self.dbConnection:prepareString(statement, ...)
return self.dbConnection:query(finalString)
end
return nil
end
function MySQLManager_S:exec(statement, ...)
if (self.dbConnection) then
local finalString = self.dbConnection:prepareString(statement, ...)
return self.dbConnection:exec(finalString)
end
return nil
end
.
.
.
Alles anzeigen
Aufgerufen wird das ganze dann z.B. so:
self:exec(MySQL.saveAccountData, accountData.account_id, accountData.account_name, accountData.password, accountData.skin_id, accountData.playerName, accountData.position, accountData.rotation)
Die Datenbank selber sieht so aus:
Das funktioniert auch ganz gut, bis auf das UPDATE Statement, dort bekomme ich egal wie ich es drehe immer Fehler:
Statement
MySQL.updateAccountData = "UPDATE " .. MySQL.accountTable .. " SET account_name=`?`, password=`?`, skin_id=`?`, player_name=`?`, position=`?`, rotation=`?` WHERE account_id=?"
Fertiger Befehl
UPDATE accounts SET account_name=`'samake'`, password=`'CEB897DB44248845BACAE6617B19E30B32D15945E4EEF7E2C6FE48DF5BA903D8'`, skin_id=`258`, player_name=`'Sam@ke'`, position=`'2410.7001953125|-5.400390625|27.683460235596'`, rotation=`'0|0|302.10391235352'` WHERE account_id=1
Statement
MySQL.updateAccountData = "UPDATE " .. MySQL.accountTable .. " SET account_name=`?`, password=`?`, skin_id=`?`, player_name=`?`, position=`?`, rotation=`?` WHERE account_id=`?`"
Fertiger Befehl
UPDATE accounts SET account_name=`'samake'`, password=`'CEB897DB44248845BACAE6617B19E30B32D15945E4EEF7E2C6FE48DF5BA903D8'`, skin_id=`258`, player_name=`'Sam@ke'`, position=`'2410.7001953125|-5.400390625|27.683460235596'`, rotation=`'0|0|185.22956848145'` WHERE account_id=`1`
So was mache ich konkret falsch? Ich sehe da gerade langsam nicht mehr durch und kämpfe schon 2 Tage dran!