I have a situation where I'm running queries on several different DB's from the same file. I've gotten everything working properly, but have noticed that I get a "Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource" error from the following code. I need the $$dbconnect to supply the query with the right DB info to link. Without it it doesn't connect to the right DB to run the query against. I've tried a dozen ways to write this with no luck.
Ok, just figured out is has to do with the query running within a function. The variable $$dbconnect isn't passed inside the the function to be used in the query. Now to figure out how to pass that into the query and see if that is the real issue.
I believe that is the issue, however, I still can't get the query to execute. It says: mysql_query(): supplied argument is not a valid MySQL-Link resource. I use this same technique outside the function and it works flawlessly. I've checked $dbconnect variable inside the function and it contains the proper data, so what gives?
function create($dbconnect) {
// Check against dbase.
$q_code = "SELECT id FROM table WHERE id=id'";
$r_code = mysql_query ($q_code, $$dbconnect);
// Code does not exist.
if (mysql_num_rows($result) == 0) {}
if ($code == FALSE) {
create($dbconnect);
}
It's supposed to be that way as I'm trying to pass a variable reference to another variable. For example: I set up several DB connections.
$db1 = mysql_connect () OR die (mysql_error());
$db2 = mysql_connect () OR die (mysql_error());
$dbconnect is a variable that house which DB to connect to from another DB. So in order to get it to pass properly it has to be sent as $$dbconnect since it is a variable referencing another variable.
Anyway, I figure out that the function isn't able to access the MySQL connection script that holds $db1 and $db2 info and thus couldn't execute the query. Not sure why it couldn't access it within the function as I thought it was global, but guess not. Thanks for the help though.