Jump to content

Unable to use MySQL connection parameter


zero_ZX

Recommended Posts

Hi,

So I'm trying to use another mysql connection to complete a function of mine:

/**
* This function checks the ban status of the account.
* @return      1 if banned 
*/
function checkBan()
{
    require("./includes/wow.php");
    $result = mysql_query("SELECT * FROM wow_logon.accounts WHERE forum_acc= '.$user->data['user_id'].', $connect");
    $row = mysql_fetch_array($result);
    if($row["banned"] == "1")
    {
        return 1;
        $ban_reason = $row["banreason"];
    }
    //$user->data['user_id']
     
    mysql_close($connect);        
}

 

Inside my "wow" file, I have this:

<?PHP
// Connect to db (edit this vars)
                         $conf["host"] = "**";
                         $conf["user"] = "**";
                         $conf["password"] = "**";
                         $conf["db"] = "**";
                         $connect = mysql_connect($conf["host"],$conf["user"],$conf["password"]) or die(mysql_error());
                         mysql_select_db($conf["db"],$connect) or die(mysql_error());
?>

 

When executing my function I get:

[function.mysql-query]: Access denied for user 'nobody'@'localhost' (using password: NO)

 

So, I guess that my function doesn't use the ", $connect" parameter for some reason, any tips?

Link to comment
Share on other sites

$connect is inside your query string "..."

 

We recommend that you ALWAYS form your queries in a php variable, then put that variable into the mysql_query() statement.

 

$query = "SELECT * FROM wow_logon.accounts WHERE forum_acc= '".$user->data['user_id']."'";
$result = mysql_query($query,$connect);

 

 

Link to comment
Share on other sites

right, so there is a problem with connecting to the database with the information used in the wow.php file.

 

lets simplify it down and see what we get:

<?PHP
//New Connection atempt for wow databse
                         $host = "localhost"; //change this if the MySQL database is on a different server from this php script
                         $name = "username"; // change this to the username of an account on the db server that has permission to perform the actions that you are planning
                         $password = "password"; // the password for the account username used above
                         $db = "database"; // the database that you are going to be using - this is NOT the same as table name
                         $con = mysql_connect($host, $name, $password) or die("ERROR - unable to connexct to the server. Server reported the following:<br><br>".mysql_error());
                         $db = mysql_select_db($db, $con) or die("ERROR - Unable to change database. Server reported the following:<br><br>".mysql_error());
?>

change your query to:

$uid= $user->data['user_id']; // pull the user id into something a little easier to work with
$sql = "SELECT * FROM accounts WHERE forum_acc= '$uid'"; // build the query string - there is a reason for this!
$result = mysql_query($sql) or die("ERROR - Query Fialed while running:<br>-------------------<br>$sql<br>---------------------<br>Server Responeded with the following:<br><br>".mysql_error());
$row = mysql_fetch_array($result);

 

Make those changes and let me know how you get on.  If it's still erroring we should at least get a bit more info back.

Link to comment
Share on other sites

There's no error, it's working perfectly in another file:

 

mysql_close($con);
            require("./includes/wow.php");
            $add_game_acc = ("INSERT INTO accounts(login,encrypted_password,gm,email,flags,lastip,forum_acc) VALUES('$username','$sha1pass',0,'$email',24,'$user_ip','$last_forum_id');");
            $debug = mysql_query($add_game_acc);
            mysql_query($add_game_acc);

That's working just fine.

Link to comment
Share on other sites

I'm just trying to help you here, I can't do that if you won't work with me.

Access denied for user 'nobody'@'localhost' (using password: NO)
is a permission problem, I'm trying to break it down to find out where, nothing to say you can't change it all back once it's fixed.  Do you really have a database account that has the username "nobody" with no password?
Link to comment
Share on other sites

Have you tried echoing the variables after require()ing the file to make sure they're what they're supposed to be? It really sounds to me like something is either undefined, or inadvertently defined as an empty string.

 

require("./includes/wow.php");
echo '<pre>';
print_r($conf);
echo '</pre>';

Link to comment
Share on other sites

Array

(

    [host] => <ip>

    [user] => webmin

    [password] => <pwd>

    [db] => wow_logon

)

 

[phpBB Debug] PHP Warning: in file /home/fusion/public_html/includes/functions_user.php on line 14: mysql_fetch_array() expects parameter 2 to be long, resource given

 

Array

(

    [host] => <ip>

    [user] => webmin

    [password] => <pwd>

    [db] => wow_logon

)

 

[phpBB Debug] PHP Warning: in file /home/fusion/public_html/includes/functions_user.php on line 14: mysql_fetch_array() expects parameter 2 to be long, resource given

Link to comment
Share on other sites

You're able to reply to others, so I know you can read just fine. Why not re-read these statements:

$connect is inside your query string "..."

 

We recommend that you ALWAYS form your queries in a php variable, then put that variable into the mysql_query() statement.

 

$query = "SELECT * FROM wow_logon.accounts WHERE forum_acc= '".$user->data['user_id']."'";
$result = mysql_query($query,$connect);

 

$connect is inside your query string "..."

either your just not listening or your not properly updating your question.  Have you tried what PFMaBiSmAd suggested? if so what is your new code and what is the current error?  If not, why not?

Link to comment
Share on other sites

I doubt the error was exactly the same. If it was, that meant that you didn't save or upload the new code to the server or you are not looking at the actual file/line number where the error message states the problem is occurring at.

 

The first error you posted indicated that the mysql_query() statement attempted to form a database connection because you didn't supply one in the mysql_query() statement because the $connect variable was part of and inside your query string, not part of the mysql_query() statement.

 

The code you posted in reply #4 is definitely not what was suggested and the code you posted in reply #14 is back to the original nonsense because you are putting the $connect variable inside the string that is defining your query statement.

 

The 'fixed' code that was posted in reply #1 was a fool-proof way of insuring that you cannot mess up the query statement by mixing it up with the connection variable.

 

If you post the actual error message and the corresponding code, I'm sure someone can probably help you.

 

Edit: additionally, the code you did post in reply #4 and your error message concerning the mysql_fetch_array parameter indicates that was the actual code, not the code you just posted in reply #16. If you don't see the difference between the code I gave you, the code you came up with, and the last code you posted, it is not the same, and yes it matters exactly what your code is because computers only do exactly what there code tells them to do.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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