Forum Moderators: coopster

Message Too Old, No Replies

MySQL-Link Resource error

Know what and how to clear?

         

wruk999

7:48 pm on May 15, 2003 (gmt 0)

10+ Year Member



I have a page which includes function pages. One function page, mysql.inc.php has various function calls on it.
Back on my default page, I am trying to run an SQL query, using my sqlquery function on my include.

Here is my mysql.inc.php page section:

function sqlquery($sql) {
global $conn;

$result = mysql_query($sql,$conn) or die("Could not query MySQL: " . mysql_error());

return $result;
}

Here is the call on the default page:

<?php
$sql = "SELECT * FROM table WHERE column = '$id' AND status <> 4 ORDER BY name";
$result = sqlquery($sql);
$numofrows = sqlcountrow($result);
?>

And here is the error:
Warning: mysql_query(): 11 is not a valid MySQL-Link resource in /www/myfolder/includes/mysql.inc.php on line 28
Could not query MySQL:

If anyone can help me work out what this error is, I will greatly appreciate it. I run quite a few other SQL queries, and they work fine..just not a few on the default page.

Thanks. wruk999.

DrDoc

7:53 pm on May 15, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



What is on line 28?

mavherick

7:56 pm on May 15, 2003 (gmt 0)

10+ Year Member



It seems there's a problem with your global $conn variable. Make sure it's defined before you call the function. If other queries worked, check the order in which you call them, that might give you a clue.

mavherick

wruk999

7:57 pm on May 15, 2003 (gmt 0)

10+ Year Member



it is this line >>

$result = mysql_query($sql,$conn) or die("Could not query MySQL: " . mysql_error());

It's very strange as other functions (language picker etc) are working fine through this command!

Regards,
wruk999

wruk999

8:06 pm on May 15, 2003 (gmt 0)

10+ Year Member



mavherick,

There shouldn't be a problem with $conn as this is used with the other functions. But what did you mean by the order in which they are called?

Regards,
wruk999

mavherick

8:17 pm on May 15, 2003 (gmt 0)

10+ Year Member



Well if my memory is good, "is not a valid MySQL-Link resource" occurs if there's a problem with the $conn var in this instance. But like you said you got a bunch of queries that do work, so somewhere in your script the $conn var is set properly and other times it's not.

So basically, where's is that $conn var set? And also, anything else in your script that could possibly reset its value to something invalid?

just thoughts, could something else...

mavherick

DrDoc

8:23 pm on May 15, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well, since $conn is optional [php.net], have you tried taking it out?

I never use anything but the actual query in mysql_query()

wruk999

8:29 pm on May 15, 2003 (gmt 0)

10+ Year Member



DrDoc,
here is the error with doing that:
Could not query MySQL: No Database Selected

This ties into what maverhick is asking, 'cause here is the bit above in the mysql.inc.php page:


function sqlconnect() {
global $sqldb;
global $conn;
global $sqluser, $sqlpass, $sqlhost;

$conn = mysql_connect($sqlhost, $sqluser, $sqlpass) or loadmaintenance() or die("Could not connect to MySQL: " . mysql_error());
$selected = mysql_select_db($sqldb, $conn) or loadmaintenance() or die("Could not select database: " . mysql_error());
}

thanks for your help. wruk999

<added>that "cannot select dbase" is only occuring on the select statement in my first post. my language selector, which is used throughout, is still working, without the $conn var being present in the query string)</added>