Jump to content

MySQL


Recommended Posts

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

Link to comment

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.

Link to comment

Try this:

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

Link to comment
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.

Link to comment

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 
  

Link to comment
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.

Link to comment
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)") 
  

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