Jump to content

WARNING: db exec failed..


Marshell

Recommended Posts

Posted (edited)

Hello! Would you like to help me ? I've got this problem : dbExec failed; (1)  near "x": syntax error.                                                THANKS!

                                                                                                   dbExec failed; (1)  near "x": syntax error.  [DUP x2]

function createVehicleForPlayer(player, command, model)
    local db = exports.db:getConnection()
    local x, y, z = getElementPosition(player)
 local rotX, rotY, rotZ = getElementRotation(player)
 rotZ = rotZ * 90
 y = y + 5
 
 dbExec(db, "INSERT INTO vehicles(model, x, y, z, rotation_x, rotation_y, rotation_z) VALUES(?, ?, ?, ?, ?, ?, ?)", model, x, y, z, rotX, rotY, rotZ)
 
 local vehicleObject = createVehicle(model, x, y, z, rotX, rotY, rotZ)
 
 dbQuery(function (queryHandle)
     local results = dbPoll(queryHandle, 0)
  local vehicle = results[1]
  
  
  setElementData(vehicleObject, "id", vehicle.id)
  
 
 
 
 end, db, "SELECT id FROM vehicles ORDER BY id DESC LIMIT 1")
end
addCommandHandler("veh", createVehicleForPlayer, false, false)
 

function loadAllVehicles(queryHandle)
    local results = dbPoll(queryHandle, 0)
 
 for index, vehicle in pairs(results) do
     local vehicleObject = createVehicle(vehicle.model, vehicle.x, vehicle.y, vehicle.z, vehicle.rotation_x, vehicle.rotation_y, vehicle.rotation_z)
  
  setElementData(vehicleObject, "id", vehicle.id)
 end
end
 
 
addEventHandler("onResourceStart", resourceRoot, function()
    local db = exports.db:getConnection()
 
 dbQuery(loadAllVehicles, db, "SELECT * FROM vehicles")
end)
 
addEventHandler("onResourceStop", resourceRoot, function()
    local db = exports.db:getConnection()
    local vehicles = getElementsByType("vehicle")
 
 for index, vehicle in pairs(vehicles) do
     local id = getElementData(vehicle, "id")
  local x, y, z = getElementPosition(vehicle)
  local rotX, rotY, rotZ = getElementRotation(vehicle)
  
  dbExec(db, "UPDATE vehicles SET x=?, y=?, z=?, rotation x = ?, rotation y = ?, rotation z = ? WHERE id = ?", x, y, z, rotX, rotY, rotZ, id)
 end
end)

                                                            

Edited by Marshell
Posted (edited)

 you should fix the  insert data  , you cant insert number vaule inside string value in db

try fix your script with  tostring() and tonumber()

 

or use

 

fromJSON ()  and  toJSON()

Edited by komal

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...