Play3rPL Posted September 23, 2015 Share Posted September 23, 2015 Hello, I have to ask for Your help. This script [db.lua], that is supposed to make connection with the SQL Database doesn't work; server console gives exactly this error: [19:08:47] Starting pgs-vsystem [19:08:47] SCRIPT ERROR: [pgsgm]\pgs-vsystem\db.lua:8: '(' expected near 'connec tion' [19:08:47] ERROR: Loading script failed: [pgsgm]\pgs-vsystem\db.lua:8: '(' expec ted near 'connection' At this point, I don't have an idea, what can be wrong at line #8. Would You like to help me, please? Here's the code: --[[ Author: Play3rPL File: db.lua Purpose: Creating connection with SQL database. Shared?: No ]]-- function createDbCon connection = Connection "sqlite", SQLfilename ); if (connection) then outputServerLog ( "[iNFO] PGS-Pojazdy: Connected to database. [sql]" ); else outputServerLog ( "[WARNING] PGS-Pojazdy: Database connection couldn't be made. " ); end end addEventHandler ( "onResourceStart", resourceRoot, createDbCon); -- connection to database and creating tables if don't exist addEventHandler ( "onResourceStart", resourceRoot, function ( ) if sql.TableExists("pojazdy") then outputServerLog ( "[iNFO] PGS-Pojazdy: Database exists. Trying to load..." ); else outputServerLog ( "[WARNING] PGS-Pojazdy: Database doesn't exist. Trying to create..." ); if (!sql.TableExists("pojazdy")) then query = "CREATE TABLE IF NOT EXISTS `pojazdy` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `vehicle_model` INTEGER, `x` INTEGER, `y` INTEGER, `z` INTEGER, `rotX` INTEGER, `rotY` INTEGER, `rotZ` INTEGER, `color` VARCHAR, `upgrades` VARCHAR, `acc_name` VARCHAR, `plateText` VARCHAR )"; -- result = sql.Query(query) if (sql.TableExists("player_info")) then outputServerLog ( "[iNFO] PGS-Pojazdy: Empty database has been created. [sql]" ); else outputServerLog ( "[iNFO] PGS-Pojazdy: Database has not been created:" ); outputServerLog( sql.LastError( result ) .. "\n" ) outputServerLog ( "[DATABASE ERROR] PGS-Pojazdy: Script will not save any data." ); end else outputServerLog ( "[iNFO] PGS-Pojazdy: Empty database has been created. [sql]" ); end end ); Thank You everyone for Your help. Every help is highly appreciated! Good evening, ~ Play3rPL Link to comment
KariiiM Posted September 23, 2015 Share Posted September 23, 2015 Try that, it should work --[[ Author: Play3rPL File: db.lua Purpose: Creating connection with SQL database. Shared?: No ]]-- function createDbCon connection = dbConnect ("sqlite", "SQLfilename.db"); if (connection) then outputServerLog ( "[iNFO] PGS-Pojazdy: Connected to database. [sql]" ); else outputServerLog ( "[WARNING] PGS-Pojazdy: Database connection couldn't be made. " ); end end addEventHandler ( "onResourceStart", resourceRoot, createDbCon); -- connection to database and creating tables if don't exist addEventHandler ( "onResourceStart", resourceRoot, function ( ) if sql.TableExists("pojazdy") then outputServerLog ( "[iNFO] PGS-Pojazdy: Database exists. Trying to load..." ); else outputServerLog ( "[WARNING] PGS-Pojazdy: Database doesn't exist. Trying to create..." ); if (!sql.TableExists("pojazdy")) then query = "CREATE TABLE IF NOT EXISTS `pojazdy` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `vehicle_model` INTEGER, `x` INTEGER, `y` INTEGER, `z` INTEGER, `rotX` INTEGER, `rotY` INTEGER, `rotZ` INTEGER, `color` VARCHAR, `upgrades` VARCHAR, `acc_name` VARCHAR, `plateText` VARCHAR )"; -- result = sql.Query(query) if (sql.TableExists("player_info")) then outputServerLog ( "[iNFO] PGS-Pojazdy: Empty database has been created. [sql]" ); else outputServerLog ( "[iNFO] PGS-Pojazdy: Database has not been created:" ); outputServerLog( sql.LastError( result ) .. "\n" ) outputServerLog ( "[DATABASE ERROR] PGS-Pojazdy: Script will not save any data." ); end else outputServerLog ( "[iNFO] PGS-Pojazdy: Empty database has been created. [sql]" ); end end ); Link to comment
Play3rPL Posted September 23, 2015 Author Share Posted September 23, 2015 Hello KariiiM! Thanks for You help, I appreciate. Unfortunately, it gives still the same error, saved file, did refreshall, not working at all. Regards! Link to comment
KariiiM Posted September 23, 2015 Share Posted September 23, 2015 Play3rPL said: Hello KariiiM! Thanks for You help, I appreciate.Unfortunately, it gives still the same error, saved file, did refreshall, not working at all. Regards! You're welcome, are you using db functions for sqlite? because i see there are something not defined, i just saw it now i thought your problem was in the database connextion example; result = sql.Query(query) sql.Query ? -- is not defined same to query you tried to create a table and columns but this query is not defined in MTA at all, maybe you mean dbQuery there's no defirent between mysql and sqlite in scripting the different is sqlite create file and mysql connect your data to the web by phpMyAdmin Link to comment
TAPL Posted September 24, 2015 Share Posted September 24, 2015 You didn't put the brackets for the function createDbCon. 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