golanu21 Posted August 7, 2013 Share Posted August 7, 2013 Acum urmeaza crearea acestui tabel: function creeazaTabel() local characters = dbExec( char_db, "CREATE TABLE IF NOT EXISTS characters (id INT PRIMARY KEY NOT NULL, nume CHAR(50) NOT NULL, model INT NOT NULL, health REAL NOT NULL, posx REAL NOT NULL, posy REAL NOT NULL, posz REAL NOT NULL)") addEventHandler("onResourceStart", getRootElement(getThisResource()), creeazaTabel) ai uitat sa opresti functia ... ai uitat un end Link to comment
Unknown76 Posted August 7, 2013 Author Share Posted August 7, 2013 ai uitat sa opresti functia ... ai uitat un end Am modificat, mersi. Link to comment
golanu21 Posted August 7, 2013 Share Posted August 7, 2013 function connect(res) connection = mysql_connect("localhost", "root", "", "zombiesv", 3306) if (not connection) then if (res == getThisResource()) then cancelEvent(true, "Nu te poti conecta la baza de date.") end return nil end return nil end addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), connect, false) 2: attempt to call global mysql_connect <a nil value> Link to comment
Unknown76 Posted August 7, 2013 Author Share Posted August 7, 2013 function connect(res) connection = mysql_connect("localhost", "root", "", "zombiesv", 3306) if (not connection) then if (res == getThisResource()) then cancelEvent(true, "Nu te poti conecta la baza de date.") end return nil end return nil end addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), connect, false) 2: attempt to call global mysql_connect <a nil value> mysql_connect este deprecated. Nu se mai foloseste. Parerea mea este sa faci o resursa "mysql" si sa apelezi functia din "mysql" in celelalte resurse. -- Exemplu de conectare la MySQL local host = "localhost"; local dbname = "zombiesv"; local username = "root"; local password = ""; function connectToDB() zombie_db = dbConnect("mysql", "dbname="..dbname..";host="..host, username, password, "autoreconnect=1") return zombie_db end In celelalte resurse deschizi conexiunea prin: conn = call(getResourceFromName("mysql"), "connectToDB") EDIT: Sa nu uiti sa pui in meta.xml in resursa "mysql" linia asta: function="connectToDB" type="server"/> Link to comment
golanu21 Posted August 7, 2013 Share Posted August 7, 2013 si cum fac sa ajung in sql, ( phpmyadmin )? Link to comment
Unknown76 Posted August 7, 2013 Author Share Posted August 7, 2013 si cum fac sa ajung in sql, ( phpmyadmin )? O varianta ar fi prin phpMyAdmin. Instaleaza XAMPP (foarte bun pentru web hosting si phpMyAdmin): http://www.apachefriends.org/en/xampp.html (vine cu phpMyAdmin preinstalat) A doua varianta prin Navicat (cea mai simpla): http://www.navicat.com/ (fie vorba intre noi, se gaseste pe Filelist sa zicem pentru non-commerical purposes ) Link to comment
golanu21 Posted August 7, 2013 Share Posted August 7, 2013 eu mai exct folosesc wamp....dar tot ceva de genu fac ca sa ma conectez ? dbConnect("mysql", "dbname="..dbname..";host="..host, username, password, "autoreconnect=1") Link to comment
Unknown76 Posted August 7, 2013 Author Share Posted August 7, 2013 eu mai exct folosesc wamp....dar tot ceva de genu fac ca sa ma conectez ? dbConnect("mysql", "dbname="..dbname..";host="..host, username, password, "autoreconnect=1") Da, nu conteaza daca folosesti XAMPP sau WAMP cat timp versiunea de MySQL este up-to-date. Link to comment
golanu21 Posted August 7, 2013 Share Posted August 7, 2013 cumva mai tre sa fac dala cu setting.xml... ? ca la valhalla ? Link to comment
Unknown76 Posted August 7, 2013 Author Share Posted August 7, 2013 cumva mai tre sa fac dala cu setting.xml... ? ca la valhalla ? Nu. Link to comment
golanu21 Posted August 7, 2013 Share Posted August 7, 2013 -- Exemplu de conectare la MySQL local host = "localhost"; local dbname = "zo"; local username = "root"; local password = ""; function connectToDB() zombie_db = dbConnect("mysql", "dbname="..dbname..";host="..host, username, password, "autoreconnect=1") return zombie_db end function creeazaTabel() local characters = dbExec( zombie_db, "CREATE TABLE characters (id INT PRIMARY KEY NOT NULL, nume CHAR(50) NOT NULL, model INT NOT NULL, health REAL NOT NULL, posx REAL NOT NULL, posy REAL NOT NULL, posz REAL NOT NULL)") end addEventHandler("onResourceStart", getRootElement(getThisResource()), creeazaTabel) WARNING: cdb\server.lua:15: Bad argument @ 'dbExec' [Expected db-connection at argument 1, got nil] Link to comment
Unknown76 Posted August 7, 2013 Author Share Posted August 7, 2013 -- Exemplu de conectare la MySQL local host = "localhost"; local dbname = "zo"; local username = "root"; local password = ""; function connectToDB() zombie_db = dbConnect("mysql", "dbname="..dbname..";host="..host, username, password, "autoreconnect=1") return zombie_db end function creeazaTabel() local characters = dbExec( zombie_db, "CREATE TABLE characters (id INT PRIMARY KEY NOT NULL, nume CHAR(50) NOT NULL, model INT NOT NULL, health REAL NOT NULL, posx REAL NOT NULL, posy REAL NOT NULL, posz REAL NOT NULL)") end addEventHandler("onResourceStart", getRootElement(getThisResource()), creeazaTabel) WARNING: cdb\server.lua:15: Bad argument @ 'dbExec' [Expected db-connection at argument 1, got nil] Am modificat in postul initial functia, verifica postul. Si nu uita sa precizezi id-ul pedului, nu lasa idmodel. EDIT: Acum vad ca ai editat postul. Nu ai facut conexiunea bine. Inainte de crearea tabelului pune: zombie_db = connectToDB() Link to comment
golanu21 Posted August 7, 2013 Share Posted August 7, 2013 ce nui bn ? Edit: acum am vazut si eu ca ai editat ) Edit2: merge perfect, mersi P.S.: tu ai merita sa fi moderator , acum sincer Link to comment
golanu21 Posted August 7, 2013 Share Posted August 7, 2013 dbExec( char_db, "UPDATE `??` SET `??`=?", tableName, columnName, columnValue ) aici trebuie sa modific si '''''??'''' sau doar tablename column.. etc Link to comment
Unknown76 Posted August 7, 2013 Author Share Posted August 7, 2013 dbExec( char_db, "UPDATE `??` SET `??`=?", tableName, columnName, columnValue ) aici trebuie sa modific si '''''??'''' sau doar tablename column.. etc Doar tablename, column etc. '??' = pentru tabel/coloane ? = pentru valori (ai grija ca dupa query sa fie scrise in ordine numele tabelelor si al coloanelor precum si al valorilor) Link to comment
golanu21 Posted August 7, 2013 Share Posted August 7, 2013 dbExec( char_db, "UPDATE `??` SET `??`=?", tableName, columnName, columnValue ) aici trebuie sa modific si '''''??'''' sau doar tablename column.. etc Doar tablename, column etc. '??' = pentru tabel/coloane ? = pentru valori (ai grija ca dupa query sa fie scrise in ordine numele tabelelor si al coloanelor precum si al valorilor) ai putea sa imi oferi un exemplu te rog ?, ca de exemplu am facut asta dar nu functioneaza.. in DB arata 0 addEventHandler("onPlayerQuit", getRootElement(), function () zombie_db = connectToDB() dbExec( zombie_db, "UPDATE `??` SET `??`=?", characters, health, getElementHealth(source) ) end) si imi da o eroare : WARNING: cdb\server.lua:31: dbExec failed; (1146) Table 'zo.''' doesn't exist Link to comment
Unknown76 Posted August 7, 2013 Author Share Posted August 7, 2013 dbExec( char_db, "UPDATE `??` SET `??`=?", tableName, columnName, columnValue ) aici trebuie sa modific si '''''??'''' sau doar tablename column.. etc Doar tablename, column etc. '??' = pentru tabel/coloane ? = pentru valori (ai grija ca dupa query sa fie scrise in ordine numele tabelelor si al coloanelor precum si al valorilor) ai putea sa imi oferi un exemplu te rog ?, ca de exemplu am facut asta dar nu functioneaza.. in DB arata 0 addEventHandler("onPlayerQuit", getRootElement(), function () zombie_db = connectToDB() dbExec( zombie_db, "UPDATE `??` SET `??`=?", characters, health, getElementHealth(source) ) end) si imi da o eroare : WARNING: cdb\server.lua:31: dbExec failed; (1146) Table 'zo.''' doesn't exist Ai mare grija cand faci diferenta dintre un string (sir de caractere) si o variabila. Pune "" cand faci referire directa la ceva: dbExec( zombie_db, "UPDATE `??` SET `??`=?", "characters", health, getElementHealth(source) ) Sau cum ai pus tu acolo characters fara trebuie sa mai adaugi ceva: characters = "characters" dbExec( zombie_db, "UPDATE `??` SET `??`=?", characters, health, getElementHealth(source) ) Link to comment
golanu21 Posted August 7, 2013 Share Posted August 7, 2013 aaa, da corect.. mersi mult ca ma ajuti Link to comment
golanu21 Posted August 7, 2013 Share Posted August 7, 2013 alta eroare -- Exemplu de conectare la MySQL local host = "localhost"; local dbname = "zo"; local username = "root"; local password = ""; function connectToDB() zombie_db = dbConnect("mysql", "dbname="..dbname..";host="..host, username, password, "autoreconnect=1") return zombie_db end function creeazaTabel() zombie_db = connectToDB() local characters = dbExec( zombie_db, "CREATE TABLE IF NOT EXISTS characters (id INT PRIMARY KEY NOT NULL, nume CHAR(50) NOT NULL, model INT NOT NULL, health REAL NOT NULL, posx REAL NOT NULL, posy REAL NOT NULL, posz REAL NOT NULL)") end addEventHandler("onResourceStart", getRootElement(getThisResource()), creeazaTabel) addEventHandler("onPlayerJoin", getRootElement(), function () zombie_db = connectToDB() x, y, z = getElementPosition(source) dbExec( zombie_db, "INSERT INTO characters (nume, model, health, posx, posy, posz) VALUES (?,?,?,?,?,?)", getPlayerName(source), getElementModel(source), getElementHealth(source), x, y, z ) end) addEventHandler("onPlayerQuit", getRootElement(), function () zombie_db = connectToDB() dbExec( zombie_db, "UPDATE `??` SET `??`=`?`", "characters", health, getElementHealth(source)) end ) WARNING: cdb\server.lua:32: dbExec failed; (1054) Unknown column '''' in 'field list' Link to comment
Unknown76 Posted August 7, 2013 Author Share Posted August 7, 2013 alta eroare -- Exemplu de conectare la MySQL local host = "localhost"; local dbname = "zo"; local username = "root"; local password = ""; function connectToDB() zombie_db = dbConnect("mysql", "dbname="..dbname..";host="..host, username, password, "autoreconnect=1") return zombie_db end function creeazaTabel() zombie_db = connectToDB() local characters = dbExec( zombie_db, "CREATE TABLE IF NOT EXISTS characters (id INT PRIMARY KEY NOT NULL, nume CHAR(50) NOT NULL, model INT NOT NULL, health REAL NOT NULL, posx REAL NOT NULL, posy REAL NOT NULL, posz REAL NOT NULL)") end addEventHandler("onResourceStart", getRootElement(getThisResource()), creeazaTabel) addEventHandler("onPlayerJoin", getRootElement(), function () zombie_db = connectToDB() x, y, z = getElementPosition(source) dbExec( zombie_db, "INSERT INTO characters (nume, model, health, posx, posy, posz) VALUES (?,?,?,?,?,?)", getPlayerName(source), getElementModel(source), getElementHealth(source), x, y, z ) end) addEventHandler("onPlayerQuit", getRootElement(), function () zombie_db = connectToDB() dbExec( zombie_db, "UPDATE `??` SET `??`=`?`", "characters", health, getElementHealth(source)) end ) WARNING: cdb\server.lua:32: dbExec failed; (1054) Unknown column '''' in 'field list' Acelasi lucru si pentru health => "health" Link to comment
golanu21 Posted August 7, 2013 Share Posted August 7, 2013 alta eroare -- Exemplu de conectare la MySQL local host = "localhost"; local dbname = "zo"; local username = "root"; local password = ""; function connectToDB() zombie_db = dbConnect("mysql", "dbname="..dbname..";host="..host, username, password, "autoreconnect=1") return zombie_db end function creeazaTabel() zombie_db = connectToDB() local characters = dbExec( zombie_db, "CREATE TABLE IF NOT EXISTS characters (id INT PRIMARY KEY NOT NULL, nume CHAR(50) NOT NULL, model INT NOT NULL, health REAL NOT NULL, posx REAL NOT NULL, posy REAL NOT NULL, posz REAL NOT NULL)") end addEventHandler("onResourceStart", getRootElement(getThisResource()), creeazaTabel) addEventHandler("onPlayerJoin", getRootElement(), function () zombie_db = connectToDB() x, y, z = getElementPosition(source) dbExec( zombie_db, "INSERT INTO characters (nume, model, health, posx, posy, posz) VALUES (?,?,?,?,?,?)", getPlayerName(source), getElementModel(source), getElementHealth(source), x, y, z ) end) addEventHandler("onPlayerQuit", getRootElement(), function () zombie_db = connectToDB() dbExec( zombie_db, "UPDATE `??` SET `??`=`?`", "characters", health, getElementHealth(source)) end ) WARNING: cdb\server.lua:32: dbExec failed; (1054) Unknown column '''' in 'field list' Acelasi lucru si pentru health => "health" am incercat si asa... dar tot nu functioneaza.. imd dau eroarea Link to comment
Unknown76 Posted August 7, 2013 Author Share Posted August 7, 2013 alta eroare -- Exemplu de conectare la MySQL local host = "localhost"; local dbname = "zo"; local username = "root"; local password = ""; function connectToDB() zombie_db = dbConnect("mysql", "dbname="..dbname..";host="..host, username, password, "autoreconnect=1") return zombie_db end function creeazaTabel() zombie_db = connectToDB() local characters = dbExec( zombie_db, "CREATE TABLE IF NOT EXISTS characters (id INT PRIMARY KEY NOT NULL, nume CHAR(50) NOT NULL, model INT NOT NULL, health REAL NOT NULL, posx REAL NOT NULL, posy REAL NOT NULL, posz REAL NOT NULL)") end addEventHandler("onResourceStart", getRootElement(getThisResource()), creeazaTabel) addEventHandler("onPlayerJoin", getRootElement(), function () zombie_db = connectToDB() x, y, z = getElementPosition(source) dbExec( zombie_db, "INSERT INTO characters (nume, model, health, posx, posy, posz) VALUES (?,?,?,?,?,?)", getPlayerName(source), getElementModel(source), getElementHealth(source), x, y, z ) end) addEventHandler("onPlayerQuit", getRootElement(), function () zombie_db = connectToDB() dbExec( zombie_db, "UPDATE `??` SET `??`=`?`", "characters", health, getElementHealth(source)) end ) WARNING: cdb\server.lua:32: dbExec failed; (1054) Unknown column '''' in 'field list' Acelasi lucru si pentru health => "health" am incercat si asa... dar tot nu functioneaza.. imd dau eroarea Unde ai un singur ? nu pune '?', lasa un simplu ?. Am vazut ca ai pus ghilimele acolo. Si in al doilea rand deschide tabelul cu phpMyAdmin sau Navicat sa vezi daca ti-a facut coloana. Link to comment
golanu21 Posted August 7, 2013 Share Posted August 7, 2013 local characters = dbExec( zombie_db, "CREATE TABLE IF NOT EXISTS characters (id INT PRIMARY KEY NOT NULL, nume CHAR(50) NOT NULL, model INT NOT NULL, health REAL NOT NULL, posx REAL NOT NULL, posy REAL NOT NULL, posz REAL NOT NULL)") aici e problema.. zice ca se dubleaza PRIMARY KEY Link to comment
Unknown76 Posted August 7, 2013 Author Share Posted August 7, 2013 local characters = dbExec( zombie_db, "CREATE TABLE IF NOT EXISTS characters (id INT PRIMARY KEY NOT NULL, nume CHAR(50) NOT NULL, model INT NOT NULL, health REAL NOT NULL, posx REAL NOT NULL, posy REAL NOT NULL, posz REAL NOT NULL)") aici e problema.. zice ca se dubleaza PRIMARY KEY Pai tu folosesti MySQL, totul se schimba, acum mi-am dat seama. SQLite si MySQL par la fel dar sunt in acelasi timp foarte diferite. local characters = dbExec( zombie_db, "CREATE TABLE IF NOT EXISTS characters (id INT NOT NULL AUTO_INCREMENT, nume VARCHAR(50) NOT NULL, model INT NOT NULL, health FLOAT NOT NULL, posx FLOAT NOT NULL, posy FLOAT NOT NULL, posz FLOAT NOT NULL, PRIMARY KEY (id))") Ai grija sa stergi tabelul daca l-a creat cu datele anterior gresite si dupa ruleaza iar resursa. Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now