Jump to content

Selecting a thing from SQL


Recommended Posts

Posted

okay so I was wondering how to select something like from the data base 'rpserver' and the table 'settings' and it has a MOTD line how would I be able to show that using paradise MySQL so like it shows on a outputChatBox?

How to Contact me?

Email: [email protected]

Skype: MrChamberlien

Xbox: Chamberlien

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

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

You're welcome.

P.S: "value" is the column name.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

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

Retired

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