Jump to content

Selecting a thing from SQL


Recommended Posts

local result = exports.sql:query_assoc_single ( "SELECT * FROM settings WHERE name = 'motd'" ) 
if ( result ) then 
    outputChatBox ( tostring ( result.value ) ) 
end 

Database cannot be specified when using MTA Paradise game mode, you have just one database set on "sql/mysql.lua".

Link to comment
local result = exports.sql:query_assoc_single ( "SELECT * FROM settings WHERE name = 'motd'" ) 
if ( result ) then 
    outputChatBox ( tostring ( result.value ) ) 
end 

Database cannot be specified when using MTA Paradise game mode, you have just one database set on "sql/mysql.lua".

Selecting * can be a potential performance deficiency. You should only select the columns you need, using the format;

"SELECT column1, column2, column3 FROM table WHERE column4 = 'value' LIMIT 1" 

PS: Using 'limit 1' makes the server stop the query after fetching 1 result. This is very good for increasing performance (so if the result is row 500 or 100000, it doesn't loop the other 99500 rows).

Link to comment

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...