Jump to content

MySQL


Recommended Posts

Posted
function insertToMySQL() 
    mysql_query(database, "INSERT INTRO prresourcename ( Serial, AccountName, Password ) VALUES ( Serial = '123', AccountName = 'Lala', Password = 'But' " ) 
end 
addEventHandler("onResourceStart", resourceRoot, insertToMySQL) 
  

It shows that at argument 1 is handler expected. Please don't fix the code for me just explain me what am I doing wrong¸

EDIT:

function connectToMySQL() 
local database = mysql_connect( "127.0.0.1", "root", "", "XXXXX" ) 
    if database then 
        outputDebugString ('MySQL Service -- Connected') 
    else 
        outputDebugString ("MySQL Service -- Truble") 
    end 
end 
addEventHandler("onResourceStart", resourceRoot, connectToMySQL) 

This is how I get Connection

Posted

Well, it means that the MySQL handler is invalid.

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

Because is wrong.

function insertToMySQL ( ) 
    mysql_query ( database, "INSERT INTRO prresourcename ( Serial, AccountName, Password ) VALUES ( '123', 'Lala', 'But'" ) 
end 
addEventHandler ( "onResourceStart", resourceRoot, insertToMySQL ) 

Try with that.

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

Try this:

function insertToMySQL ( ) 
    mysql_query ( database, "INSERT INTRO prresourcename ( Serial, AccountName, Password ) VALUES ( '123', 'Lala', 'But' );" ) 
end 
addEventHandler ( "onResourceStart", resourceRoot, insertToMySQL ) 

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

Copy last again.

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

Well, I use it on that syntax, but I don't use Ryden's MySQL, I use MTA built-on functions.

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

Indeed, it's easier with MTA built-on functions.

You're welcome.

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
function setData(source) 
local x,y,z = getElementPosition(source) 
local r, g, b = getPlayerNametagColor( source ) 
local isData = dbQuery( database, "SELECT * FROM prsaver WHERE serial = "..getPlayerSerial(source).."" ) 
local result = dbPoll( isData, 0 ) 
if not result then 
local qh = dbQuery -- Long code here 
dbFree( qh ) 
end 
end 

problem is that it makes pass the result even if the serial is not in.

Posted

What is your type? TEXT? VARCHAR?

If it is TEXT or VARCHAR, try use:

  
function setData ( source ) 
    local x,y,z = getElementPosition ( source ) 
    local r, g, b = getPlayerNametagColor ( source ) 
    local isData = dbQuery ( database, "SELECT * FROM prsaver WHERE serial = '" .. getPlayerSerial ( source ) .. "'" ) 
    local result = dbPoll ( isData, 0 ) 
    if result and result ~= 0 then 
        local qh = dbQuery -- Long code here 
        dbFree ( qh ) 
    end 
end 
  

Ingame nick: Cadu12

Posted
function setData ( source ) 
    local x, y, z = getElementPosition ( source ) 
    local query = dbQuery ( database, "SELECT * FROM prsaver WHERE serial = '".. getPlayerSerial ( source ) .."' LIMIT 1" ) 
    local result, numrows, errmsg = dbPoll ( query, 0 ) 
    if ( not result ) or ( type ( result ) == "table" and #numrows == 0 ) then 
       local r, g, b = getPlayerNametagColor ( source ) 
     local qh = dbQuery -- Long code here 
        dbFree ( qh ) 
    end 
end 

That'll check if the result was not found.

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

What doesn't work?

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

Copy my code again and see if it works.

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 are sure that your column name is: "serial" and not "Serial"?

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
Try this:
function insertToMySQL ( ) 
    mysql_query ( database, "INSERT INTRO prresourcename ( Serial, AccountName, Password ) VALUES ( '123', 'Lala', 'But' );" ) 
end 
addEventHandler ( "onResourceStart", resourceRoot, insertToMySQL ) 

it doesn't work because 'INTRO' is supposed to be 'INTO'.

INSERT INTO table_name (column1, column2, column3) VALUES (value1, value2, value3) 

how is this harder than mta sql functions?

mysql_query (database, "INSERT INTO prresourcename (serial, accountname, password) VALUES (1, 2, 3)") 
  

Posted

Oh, I didn't see that typo o.O.

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.

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