mysql_connect question
#1

Hey.
First the code:
pawn Код:
if(!mysql_connect(SQL_HOST, SQL_USER, SQL_DB, SQL_PASS))
    {
        print("#Warning: Could not connect to MySQL Database!");
        print("#Warning: Retrying...");
        print("-----------------------------------------------");
        if(!mysql_connect(SQL_HOST, SQL_USER, SQL_DB, SQL_PASS))
        {
            print("#Warning: Could not connect to MySQL Database!");
            print("#Warning: Retrying...");
            print("-----------------------------------------------");
            if(!mysql_connect(SQL_HOST, SQL_USER, SQL_DB, SQL_PASS))
            {
                print("#ERROR: COULD NOT CONNECT TO MYSQL-DATABASE!");
                print("-----------------------------------------------");
            }
        }
    }
    else if(mysql_connect(SQL_HOST, SQL_USER, SQL_DB, SQL_PASS))
    {
        print("#Connected to MySQL Database.");
        print("-----------------------------------------------");
    }
Okay, now my question: Why does it say "Connected to database", even when i'm just running the server on localhost and i actually dont have any internet-connection?
Did i misunderstood something in this function or is my code wrong? Please help.
Thanks.

PS: Indentation actually is correct, but the forums screwed it .
Reply
#2

I'm guessing you don't actually need 'connection to internetz' to connect to a local MySQL database from a local machine. Either that, or I just said the dumbest thing ever and someone will ban me.
Reply
#3

Quote:
Originally Posted by ettans
Посмотреть сообщение
I'm guessing you don't actually need 'connection to internetz' to connect to a local MySQL database from a local machine. Either that, or I just said the dumbest thing ever and someone will ban me.
Well, the problem is that i dont conenct to a local database, i just connect to the localhosted server.
I connect to a external database that is located on serverffs.

#edit#:
Example:

I connect over 128.0.0.1:7777 to my local server, so i actually do not need the internet. But then the filterscript wants to access to the database, located on the web under some IP, that is not necessary to post here. Although there is no actual internet connection it says it connected to database.
Reply
#4

<bump>
Does nobody have any ideas?
Also it seems that if i am really connected, mysql_num_rows never returns 0 in this code:

pawn Код:
format(query, sizeof(query), "SELECT * FROM `table` WHERE `bla` = '%s'", blubb);
mysql_query(query);
mysql_store_result();
if(mysql_num_rows()!=0)
{        
   //Is always called, when not connected to the internet. Works properly when i am connected.
}
Reply
#5

Quote:
Originally Posted by DeathOnaStick
Посмотреть сообщение
<bump>
Does nobody have any ideas?
Also it seems that if i am really connected, mysql_num_rows never returns 0 in this code:

pawn Код:
format(query, sizeof(query), "SELECT * FROM `table` WHERE `bla` = '%s'", blubb);
mysql_query(query);
mysql_store_result();
if(mysql_num_rows()!=0)
{        
   //Is always called, when not connected to the internet. Works properly when i am connected.
}
There's a reason for that, if you're not connected than the query will return 0, therefore storeresult will not work.
Reply
#6

Quote:
Originally Posted by Carlton
Посмотреть сообщение
There's a reason for that, if you're not connected than the query will return 0, therefore storeresult will not work.
Alright but my real problem still is the one of the first post. It shouldnt even call this code if the database is offline, so it would be all fine if mysql_connect would return the correct value.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)