Jump to content

SQL Database question


AMARANT

Recommended Posts

I want to learn more how to use SQL database within MTA. So I tried to create one when my resource starts. I used this:

function createSQLOnStart (res) 
  if res==getThisResource() then 
     executeSQLCreateTable ( "mostwanted", "nickname TEXT, reward NUMBER, desc TEXT" ) 
  end 
end 
addEventHandler ( "onResourceStart", getRootElement(),createSQLOnStart ) 

In the console it says "Creating new DB table mostwanted" so I figured that I did it right. But where that database is located on the server? Where can I see it like I do with 'internal.db'?

Link to comment

It's much better to create functions like "getDatabase( element, "row" ) and setDatabase( element, "row", value ) to handle database and have a smart use. if u have any questions or need help simply write a message and i will help you:)

Link to comment
It's better to use the new database functions:
dbConnect 
dbQuery 
dbExec 
dbPoll 
dbFree 

Yeah, MySQL is much better. You can use XAMPP for it (localhost). But be careful, because you must use "dbPoll" to get a table data. Then, if you want to INSERT, DELETE or UPDATE something, you can use "dbExec"

Link to comment

Try this:

    local query = dbQuery ( handler, "SELECT columnName FROM nickname WHERE columnName = ?", "AMARANT" ) 
    local result, numrows, errmsg = dbPoll ( query, -1 ) 
    if ( type ( result ) == "table" and #result == 0 or not result ) then 
        return false 
    else 
        return true 
    end 

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