Jump to content

MySQL link identifier


zero_ZX

Recommended Posts

Hi,

So my code returns this:

mysql_query() expects parameter 2 to be resource, null given

 

My query & result is:

$query = "SELECT * FROM wow_logon.accounts WHERE forum_acc = ('$userid')";

$result = mysql_query($query,$connect);

 

So, something's wrong with my connect variable:

$connect = mysql_connect($conf["host"],$conf["user"],$conf["password"]) or die(mysql_error());

                        mysql_select_db($conf["db"],$connect) or die(mysql_error());

 

So I don't get why it doesn't work, perhaps the select db isn't parsed, but it's told which database to use in the query :/

Any help is much appreciated.

Link to comment
https://forums.phpfreaks.com/topic/249147-mysql-link-identifier/
Share on other sites

If this query is inside a function then you need to pass the $connect variable into that function.

 

Also, if you only have one database connection you can do away with $connect entirely, php will just use the open connection for everything.

 

-Dan

Full code:

require("./includes/wow.php");
$userid = $user->data['user_id'];

/**
* This function checks the ban status of the account.
* @return      1 if banned 
*/
function checkBan()
{ 
    $query = "SELECT * FROM wow_logon.accounts WHERE forum_acc = ('$userid')";
    $result = mysql_query($query,$connect);
    if(!$result)
        die(mysql_error());
    $row = mysql_fetch_array($result);
    if($row["banned"] == "1")
    {
        return 1;
        //$ban_reason = $row["banreason"];
    }
           
}

 

Yes, it's inside a function, but what do you mean that i have to pass it?

You either have to pass the variable via function arguments, or register it as a global, or the easiest way is to just take the resource link off of the query

 

Option 1: function foo($id_link) { mysql_query($sql, $id_link); }

 

Option 2: function foo() { global $id_link; mysql_query($sql, $id_link); }

 

Option 3: $result = mysql_query($query); (Of course you do have to have an open connection, but PHP should find the open connection this way.)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.