You didn’t build resource. You probably downloaded source code instead of release version.
Try adjusting connectTimeout
to some higher value by adding to connection string. Afaik this issue can be only reproduced on very low performance servers.
Then it may be your connection string. Run ensure oxmysql
command and will show you output error. Also I recommend to put oxmysql
as dependency
into other resource fxmanifest so it won’t start without oxmysql.
i dont understand add to connection string ? can you explain this ?
oh i see , After i edit the mysql_connection_string , 1.8.0 fully working , thanks for help
After about 2 or 3 hours of using oxmysql on the server, The script does not stop but does not execute any queries until i restart the script
Details are not optional
RegisterNetEvent('esx_ambulancejob:setDeathStatus')
AddEventHandler('esx_ambulancejob:setDeathStatus', function(isDead)
local xPlayer = ESX.GetPlayerFromId(source)
if type(isDead) == 'boolean' then
exports.oxmysql:execute('UPDATE users SET is_dead = @isDead WHERE identifier = @identifier', {
['@identifier'] = xPlayer.identifier,
['@isDead'] = isDead
})
end
end)
Is this right? or wrong?
can you correct my code? so i know where im wrong
exports.oxmysql:update('UPDATE users SET is_dead = ? WHERE identifier = ? ', {isDead, xPlayer.identifier})
In fact, it’s not too difficult, I hope you can understand it yourself
Don’t bother changing your functions like that, you can continue using mysql-async functions; at this point the resource is basically a drop-in for it.
For v2.0.0 it’ll be the preferred method for Lua for a few reasons already provided in a post on the repo.
hello I am the msql in the server.cfg but when I run it is another ip for me and suddenly it can not connect
thank you in advance for resuming them
Hey all,
Sooo, I am trying to understand synced queries, but I can’t seem to get any return value.
--lua
function CreateNewTicket(_reporterUID, _reportedUID, _reporterName, _reportedName, _reportType, _description)
local retval = nil
local id = exports.oxmysql:insert('INSERT INTO `tickets` (reporterUID, reportedUID, reporterName, reportedName, reportType, reportDate, description) VALUES (?, ?, ?, ?, ?, ?, ?) ', {_reporterUID, _reportedUID, _reporterName, _reportedName, _reportType, tonumber(os.time()), _description})
if id ~= nil then
print(id)
local result = exports.oxmysql:execute('SELECT * FROM `tickets` WHERE `uid` = ?', {id})
if result ~= nil then
serverTickets[tonumber(result[1].uid)] = result[1]
retval = tonumber(result[1].uid)
return retval
end
else
print('no id return')
end
end
From the docs, I understand that on the insert column, I should receive the insertid
of the query. I think that’s the autoindex value (named ‘uid’ in my table).
Even if it isn’t, exports.oxmysql:execute()
also returns nil when trying to do a synced query.
Hello, I’m pretty sure that you have to use exports.oxmysql:insertSync
to do synced insert.
Same goes for exports.oxmysql:executeSync
.
You can take a look at the wrapper.lua for them.
v1.9.0 is currently available as a pre-release pending some testing and feedback from the community. This deprecates all the old exports and encourages the use of @oxmysql/lib/MySQL.lua
in fxmanifest.
See v1.9.0 - lib/MySQL and export deprecation · Issue #77 · overextended/oxmysql · GitHub for more information, Releases · overextended/oxmysql · GitHub to see the release.
We’re pretty much 100% compatible with mysql-async and should work with a simple drop-in replacement at this point.
PS. You’ll save yourself a lot of trouble using replace all on your resources directory.
using the current mysql functionality replace for oxmysql
was giving “object is not a string” error, may have been in es_extended 1.1, it showed for my esx_status but also for es_extended, not too sure what was causing it.
My opinion
It feels sad to me to lose the differences between oxmysql and mysql-async with oxmysql using the “bad” (to me) functions names from mysql-async (especially the sync and async confusion).
I know that you’re doing this to be able to transition from one another easily, but I don’t feel like this should be the recommended way to use it. (I kinda liked using exports ¯\_(ツ)_/¯ )
An idea of wrapper
What do you think about having a single function for async and sync which (so one for insert, execute…) :
- if there are no callback functions, will return a promise that the script have to await itself ? Kinda like using
await
in js/ts. - else, if there is a callback function, will call this function with the result.
Question between exports and the lib
How big is the performance loss between using the new exports with _async
and _callback
and using the lib with MySQL.Sync
and MySQL.Async
(and having me to add the file to the fxmanifest in each scripts) ?
PS : I love the work you have done guys and you can do whatever you feel is the best.
I can set it up with more accurate function aliases for people who want to explicitly require oxmysql; anythingusing fetchSingle and prepare won’t work with mysql-async anyway.
There are plenty of circumstances you might not need the query result so forcibly awaiting the promise to resolve when there’s no callback function isn’t necessary and would potentially cause a lot of resources to needlessly yield.
It’s incredibly minor; with the way exports work you have to go through a couple of metatables with index methods.
exports.oxmysql will trigger __index(self, resource)
and return a new metatable with its own __index
function.
MySQL.Sync.prepare('SELECT identifier from users WHERE lastname = ?', {'Linden'})
10,000 times is about ~1.2s faster than a direct export, on top of whatever garbage collection stuff happens in the background so it’s nothing major, however we do get other benefits which I’ll be improving upon later.
- Compatibility with older resources without having to convert
- Cached resource name sending to oxmysql, rather than having to call
GetInvokingResource
(JS native invocation is slow) - Creating Lua promises within the resource uses less CPU and memory than unwrapping
__cfx_async_retval
- Catch problematic queries before they trigger the export with the
safeArgs
function, making it easier to find the source
As for oxmysql specific alises
What syntax would you like? I was thinking like
MySQL.fetchSingle
MySQL.fetchSingle.await
Assuming there’s no weirdness with the metatable __call and __index so it’s not doing unneccesary function creation anyway.
If I do introduce new function aliases then it needs to make sense and actually have a good name before it makes some weird new standard.