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?

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

Posted

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

Posted

The server seem like it can't get the column and table...

I've edited the code again, if there's no debugstring then the column doesn't exit. and if there is then the table granted doesn't exit.

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 

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.

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

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