zero_ZX Posted October 14, 2011 Share Posted October 14, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/249147-mysql-link-identifier/ Share on other sites More sharing options...
teynon Posted October 14, 2011 Share Posted October 14, 2011 Please post full code and the exact error. Quote Link to comment https://forums.phpfreaks.com/topic/249147-mysql-link-identifier/#findComment-1279490 Share on other sites More sharing options...
ManiacDan Posted October 14, 2011 Share Posted October 14, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/249147-mysql-link-identifier/#findComment-1279492 Share on other sites More sharing options...
zero_ZX Posted October 14, 2011 Author Share Posted October 14, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/249147-mysql-link-identifier/#findComment-1279514 Share on other sites More sharing options...
teynon Posted October 15, 2011 Share Posted October 15, 2011 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.) Quote Link to comment https://forums.phpfreaks.com/topic/249147-mysql-link-identifier/#findComment-1279530 Share on other sites More sharing options...
KevinM1 Posted October 15, 2011 Share Posted October 15, 2011 Do NOT use 'global'. EVER. It's entirely unnecessary and is the path down which horrible code is written. Quote Link to comment https://forums.phpfreaks.com/topic/249147-mysql-link-identifier/#findComment-1279542 Share on other sites More sharing options...
ManiacDan Posted October 15, 2011 Share Posted October 15, 2011 Agreed, don't use globals. Option 1 is most correct, but 3 is most common. Quote Link to comment https://forums.phpfreaks.com/topic/249147-mysql-link-identifier/#findComment-1279566 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.