Not sure if itâs just me, but using MySQL Procedures with oxmysql:execute seems to just kill my server with no error logs or trace, tested with this procedure which works perfectly with ghmattimysql:
Use exports.oxmysql:fetch() instead of MySQL.Async.fetchAll() for example.
Remove mysql-async lib from fxmanifest.lua to reduce memory overhead.
Edit some queries if they need to be. I have prepared experimental backward compatibility with mysql-async parameters written in @param format, but it would be better to use unnamed ? or named :param placeholders.
Test everything before going to production.
Also there are some known issues or rather incompabilities between old node-mysql and newer used node-mysql2. I have written some on github page under issues but from head I remember that:
You can´t pass nil as parameter value,
TIMESTAMP is returning table value / date string instead of unix timestamp,
TINYINT(1) is not converting to boolean but stays as number,
You cannot and shouldn´t concatenate strings in query
Oxmysql is preparing and storing every query into cache to get faster results. This cache is default limited to approx. 16000 queries. Instead of concatenating you should use placeholders (:param or ?) and pass required values as parameters.
Example:
-- bad query, unsanitized, possible SQL injection and fills up prepared statement cache!
exports.oxmysql:fetch('SELECT * FROM `users` WHERE `identifier` = '..license)
-- using parameters, sanitized, query is saved only once into cache
exports.oxmysql:fetch('SELECT * FROM `users` WHERE `identifier` = ?', { xPlayer.identifier })
exports.oxmysql:fetch('SELECT * FROM `users` WHERE `identifier` = :license', { license = xPlayer.identifier })
-- if you want to pass parameter as column use ?? (haven´t tested properly yet)
exports.oxmysql:fetch('SELECT ?? FROM `users` WHERE `identifier` = ?', {'group', xPlayer.identifier })
I might be an idiotâŚbut how can you use passwords with "@" in them, using this format? For now, I just made a different account in the database, but knowing how to use @ would be nice too.
Could the default convar mysql_connection_string be changed so we can used mysql-async and oxmysql simultaneously. This allows to start converting from one to the other progressively.
Itâll come, but whatâs the point of overly complicated passwords? Prevent access from outside localhost and require ssh if you want to connect via heidi or whatever.
If your database is hosted separately from the server there is a way to setup a connection via ssh but youâd need to take a look at the node package.
This style of connection string already works with mysql-async/ghmattimysql.
Why do you need it? Unless your SQL server itself isnât running or you have connection/database issues then itâs ready from the moment oxmysql has started.
Just replace those functions and wrap the entire code block in an async export
exports.oxmysql.fetch(query, params, function(result)
-- now use your results
exports.oxmysql:fetch('SELECT * FROM users WHERE lastname = ?', {'Linden'}, function(async)
print(async[1].firstname)
local sync = exports.oxmysql:fetchSync('SELECT * FROM users WHERE lastname = ?', {'Linden'})[1]
print(sync.firstname)
end)
Both of these give the same result for me, but if youâre looking to retrieve a single row you should use single rather than fetch.
exports.oxmysql:single('SELECT * FROM users WHERE lastname = ?', {'Linden'}, function(async)
print(async.firstname)
local sync = exports.oxmysql:singleSync('SELECT * FROM users WHERE lastname = ?', {'Linden'})
print(sync.firstname)
end)