Jump to content

Returns nil... Why?


GTX

Recommended Posts

Posted

Hello. I was trying to make "protection" for my script.

function CHECKING() 
    result = mysql_query(connect_mysql_check, "SELECT name FROM granted") 
    if (result) then while true do 
        local row = mysql_fetch_assoc(result) 
         
        if not row then 
            break end 
             
            if getParticalServerName(row.name) then 
                CONNECT() 
            else 
  
                WRONG() 
            end 
        end 
    end 
    mysql_free_result(result) 
end 
  
connect_mysql_check = mysql_connect(host, user, password, database_, 3306, "/var/run/mysqld/mysqld.sock") 
if not connect_mysql_check then 
  outputChatBox("#FF8800[TOPTIMES] #FF6565Could not connect with MySQL Server.", getRootElement(), 255, 255, 255, true) 
else 
  setTimer(CHECKING, 500, 1) 
end 

local row = mysql_fetch_assoc(result) at line 4 returns nil. Why?

Do you require a paid scripter? Contact me! (Unavailable) Currently I am experienced in Lua, PHP, HTML, CSS, SQL and JS.

Developer and owner of

https://projectbea.st - Project Beast
Posted (edited)

try this:

function CHECKING() 
    result = mysql_query(connect_mysql_check, "SELECT * FROM granted") 
    if (result) then 
        local row = mysql_fetch_assoc(result) 
        
        if not row then 
         errno=mysql_errno (connect_mysql_check) 
         outputDebugString("Sorry, the result was not returned. Here's a error number: "..errno.." .",1) 
            break end 
            
            if getParticalServerName(row.name) then 
                CONNECT() 
            else 
  
                WRONG() 
            end 
        end 
    end 
    mysql_free_result(result) 

Edited by Guest

My in-game name: Jaysds1

Retired CMG Scripter

World Of Tanks GameMode (Open-Source): https://github.com/Jaysds1/mtasa-wot-gamemode

Online GUI-Editor (WIP): https://forum.mtasa.com/topic/47678-online-gui-editor/

 

sE5Qm.png

TiV3C.png

img.php?id=0&text=Lua%20Scripter

Posted

Doesn't work.

Do you require a paid scripter? Contact me! (Unavailable) Currently I am experienced in Lua, PHP, HTML, CSS, SQL and JS.

Developer and owner of

https://projectbea.st - Project Beast
Posted

I'd like to use these, but in this case I will use mysql_connect, mysql_query...

I can't find solution why it returns nil...

Do you require a paid scripter? Contact me! (Unavailable) Currently I am experienced in Lua, PHP, HTML, CSS, SQL and JS.

Developer and owner of

https://projectbea.st - Project Beast
Posted

0 came out.

Do you require a paid scripter? Contact me! (Unavailable) Currently I am experienced in Lua, PHP, HTML, CSS, SQL and JS.

Developer and owner of

https://projectbea.st - Project Beast
Posted

Which table? row?

Do you require a paid scripter? Contact me! (Unavailable) Currently I am experienced in Lua, PHP, HTML, CSS, SQL and JS.

Developer and owner of

https://projectbea.st - Project Beast
Posted

"name" is column. I want to get rows and if row matches server name, function CONNECT activates, else WRONG activates.

Do you require a paid scripter? Contact me! (Unavailable) Currently I am experienced in Lua, PHP, HTML, CSS, SQL and JS.

Developer and owner of

https://projectbea.st - Project Beast
Posted

Hmm, I think mysql_fetch_assoc is returning nil but I don't know why.

Do you require a paid scripter? Contact me! (Unavailable) Currently I am experienced in Lua, PHP, HTML, CSS, SQL and JS.

Developer and owner of

https://projectbea.st - Project Beast
Posted

oh, snap, srry, I was looking at something else

EDIT: try this:

connect_mysql_check = mysql_connect(host, user, password, database_, 3306, "/var/run/mysqld/mysqld.sock") 
if not connect_mysql_check then 
  outputChatBox("#FF8800[TOPTIMES] #FF6565Could not connect with MySQL Server.",root, 255, 255, 255, true) 
else 
  setTimer(CHECKING, 500, 1) 
end 
  
function CHECKING() 
    result = mysql_query(connect_mysql_check, "SELECT name FROM granted") 
    if (result) then 
        local row = mysql_fetch_assoc(result) 
        if not row then outputDebugString("Sorry, but the row was not returned") end 
            if getParticalServerName(row.name) then 
                CONNECT() 
            else 
  
                WRONG() 
            end 
    end 
    mysql_free_result(result) 
end 

My in-game name: Jaysds1

Retired CMG Scripter

World Of Tanks GameMode (Open-Source): https://github.com/Jaysds1/mtasa-wot-gamemode

Online GUI-Editor (WIP): https://forum.mtasa.com/topic/47678-online-gui-editor/

 

sE5Qm.png

TiV3C.png

img.php?id=0&text=Lua%20Scripter

Posted
Hello. I was trying to make "protection" for my script.
function CHECKING() 
    result = mysql_query(connect_mysql_check, "SELECT name FROM granted") 
    if (result) then while true do 
        local row = mysql_fetch_assoc(result) 
         
        if not row then 
            break end 
             
            if getParticalServerName(row.name) then 
                CONNECT() 
            else 
  
                WRONG() 
            end 
        end 
    end 
    mysql_free_result(result) 
end 
  
connect_mysql_check = mysql_connect(host, user, password, database_, 3306, "/var/run/mysqld/mysqld.sock") 
if not connect_mysql_check then 
  outputChatBox("#FF8800[TOPTIMES] #FF6565Could not connect with MySQL Server.", getRootElement(), 255, 255, 255, true) 
else 
  setTimer(CHECKING, 500, 1) 
end 

local row = mysql_fetch_assoc(result) at line 4 returns nil. Why?

I think MySQL need ` `.

Like this:

mysql_query ( connect_mysql_check, "SELECT `name` FROM `granted`" ) 

Also, check if connect_mysql_check returns 1.

EPT Team Server Development: 0%

Learning C++ | C++ is amazing xD

Posted
I think MySQL need ` `.

Like this:

mysql_query ( connect_mysql_check, "SELECT `name` FROM `granted`" ) 

Also, check if connect_mysql_check returns 1.

Oh,ya, nice thinking, i totally forgot about that part, nice work

and the connect_mysql_check returned...

My in-game name: Jaysds1

Retired CMG Scripter

World Of Tanks GameMode (Open-Source): https://github.com/Jaysds1/mtasa-wot-gamemode

Online GUI-Editor (WIP): https://forum.mtasa.com/topic/47678-online-gui-editor/

 

sE5Qm.png

TiV3C.png

img.php?id=0&text=Lua%20Scripter

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