zero_ZX Posted October 12, 2011 Share Posted October 12, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/248958-unable-to-use-mysql-connection-parameter/ Share on other sites More sharing options...
PFMaBiSmAd Posted October 12, 2011 Share Posted October 12, 2011 $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); Quote Link to comment https://forums.phpfreaks.com/topic/248958-unable-to-use-mysql-connection-parameter/#findComment-1278537 Share on other sites More sharing options...
zero_ZX Posted October 12, 2011 Author Share Posted October 12, 2011 Thanks for the info Any one else got any idea of why? Quote Link to comment https://forums.phpfreaks.com/topic/248958-unable-to-use-mysql-connection-parameter/#findComment-1278600 Share on other sites More sharing options...
Muddy_Funster Posted October 12, 2011 Share Posted October 12, 2011 Thanks for the info Any one else got any idea of why? yip I do $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? Quote Link to comment https://forums.phpfreaks.com/topic/248958-unable-to-use-mysql-connection-parameter/#findComment-1278604 Share on other sites More sharing options...
zero_ZX Posted October 12, 2011 Author Share Posted October 12, 2011 My new code is as recommended: $result = mysql_query("SELECT * FROM wow_logon.accounts WHERE forum_acc= '".$user->data['user_id']."'"); $row = mysql_fetch_array($result, $connect); Error: exactly the same Quote Link to comment https://forums.phpfreaks.com/topic/248958-unable-to-use-mysql-connection-parameter/#findComment-1278616 Share on other sites More sharing options...
Muddy_Funster Posted October 12, 2011 Share Posted October 12, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/248958-unable-to-use-mysql-connection-parameter/#findComment-1278656 Share on other sites More sharing options...
zero_ZX Posted October 12, 2011 Author Share Posted October 12, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/248958-unable-to-use-mysql-connection-parameter/#findComment-1278663 Share on other sites More sharing options...
Muddy_Funster Posted October 12, 2011 Share Posted October 12, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/248958-unable-to-use-mysql-connection-parameter/#findComment-1278682 Share on other sites More sharing options...
zero_ZX Posted October 12, 2011 Author Share Posted October 12, 2011 No, that's why i defined the username, password, host (which is not local) etc in wow.php It just seems to be unable to read it or use it for some reason. Quote Link to comment https://forums.phpfreaks.com/topic/248958-unable-to-use-mysql-connection-parameter/#findComment-1278704 Share on other sites More sharing options...
Pikachu2000 Posted October 12, 2011 Share Posted October 12, 2011 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>'; Quote Link to comment https://forums.phpfreaks.com/topic/248958-unable-to-use-mysql-connection-parameter/#findComment-1278711 Share on other sites More sharing options...
zero_ZX Posted October 12, 2011 Author Share Posted October 12, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/248958-unable-to-use-mysql-connection-parameter/#findComment-1278723 Share on other sites More sharing options...
Pikachu2000 Posted October 12, 2011 Share Posted October 12, 2011 mysql_fetch_array doesn't get the connection resource passed to it. The second parameter is for the result type. Quote Link to comment https://forums.phpfreaks.com/topic/248958-unable-to-use-mysql-connection-parameter/#findComment-1278725 Share on other sites More sharing options...
zero_ZX Posted October 13, 2011 Author Share Posted October 13, 2011 Yep.. but why? :/ Quote Link to comment https://forums.phpfreaks.com/topic/248958-unable-to-use-mysql-connection-parameter/#findComment-1278879 Share on other sites More sharing options...
Pikachu2000 Posted October 13, 2011 Share Posted October 13, 2011 Because that's the way the function works. Did you read the manual entry? Quote Link to comment https://forums.phpfreaks.com/topic/248958-unable-to-use-mysql-connection-parameter/#findComment-1278977 Share on other sites More sharing options...
zero_ZX Posted October 13, 2011 Author Share Posted October 13, 2011 Yea I see, I still wonder why this doesn't work then: $result = mysql_query("SELECT * FROM wow_logon.accounts WHERE forum_acc= '".$user->data['user_id']."', $connect"); It doesn't seem to understand the ,$connect part.. Quote Link to comment https://forums.phpfreaks.com/topic/248958-unable-to-use-mysql-connection-parameter/#findComment-1278990 Share on other sites More sharing options...
Philip Posted October 13, 2011 Share Posted October 13, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/248958-unable-to-use-mysql-connection-parameter/#findComment-1279048 Share on other sites More sharing options...
zero_ZX Posted October 13, 2011 Author Share Posted October 13, 2011 $query = "SELECT * FROM wow_logon.accounts WHERE forum_acc= '".$user->data['user_id']."'"; $result = mysql_query($query,$connect); -> same error, not a bit changed, sorry if I didn't make that clear enough at reply #4 :/ Quote Link to comment https://forums.phpfreaks.com/topic/248958-unable-to-use-mysql-connection-parameter/#findComment-1279061 Share on other sites More sharing options...
PFMaBiSmAd Posted October 13, 2011 Share Posted October 13, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/248958-unable-to-use-mysql-connection-parameter/#findComment-1279083 Share on other sites More sharing options...
PFMaBiSmAd Posted October 13, 2011 Share Posted October 13, 2011 Never-mind, managed to quote my own post instead of modifying it. Quote Link to comment https://forums.phpfreaks.com/topic/248958-unable-to-use-mysql-connection-parameter/#findComment-1279091 Share on other sites More sharing options...
zero_ZX Posted October 14, 2011 Author Share Posted October 14, 2011 we are getting somewhere, seems like this was the reason: mysql_close($connect); (which is the very last bit of my code..) thanks a lot Quote Link to comment https://forums.phpfreaks.com/topic/248958-unable-to-use-mysql-connection-parameter/#findComment-1279235 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.