PC Nerd Posted January 25, 2008 Share Posted January 25, 2008 Hi, Im getting this error : Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in Database_link.inc on line 22 that line is: $QUERY = mysql_query($SQL, $DB_Server) or die(mysql_error());# or die ("Failed Query"); now the entire DB Wrapper file ive created is here: <?php function CONNECT_MYSQL_DATABASE() { $host = "localhost"; #usually localhost $account = "<>"; # username for access. eg. root $password = "<>"; $db_name = "<>"; #name of database on the server that you want to connect. #global $db_type; #$db_type = 4.1; # MySQL version $DB_Server = mysql_connect($host, $account, $password) or die(mysql_error());# or die ("Cannot connect to a database. Please try again later"); $DB_Server = mysql_select_db($db_name, $DB_Server) or die("Cannot select the database. Please try again later."); return $DB_Server; } function MYSQL_DATABASE_QUERY($SQL, $DB_Server) { $QUERY = mysql_query($SQL, $DB_Server) or die(mysql_error());# or die ("Failed Query"); return $QUERY; } function MYSQL_GET_ARRAY($QUERY) { $ROW = mysql_fetch_array($QUERY) or die("Cannot retreive data"); return $ROW; } function CLOSE($DB_Server) { @mysql_close($DB_Server);# or die("Cannot close connection"); } $DB_Server = CONNECT_MYSQL_DATABASE(); ?> as you can see ive got the connection to diaplay the error if it fails. However I can seem to figure this out why its not working. im callling my function like this: $QUERY = MYSQL_DATABASE_QUERY($SQL, $DB_Server); so with other code in between its: require("Database_link.inc"); #the full fule above. $SQL = "THE SQL"; $QUERY = MYSQL_DATABASE_QUERY($SQL, $DB_Server); however its raising that error... : can anyone see what is happening? Link to comment https://forums.phpfreaks.com/topic/87706-solved-mysql_qyer-is-not-a-valid-mysql-resource/ Share on other sites More sharing options...
ziv Posted January 25, 2008 Share Posted January 25, 2008 lets take a look at your code: <?php function MYSQL_DATABASE_QUERY($SQL, $DB_Server) { $QUERY = mysql_query($SQL, $DB_Server) or die(mysql_error());# or die ("Failed Query"); return $QUERY; } are you sure you send to this function mysql-resource as the first parameter? if you use the return value of this function: <?php function CONNECT_MYSQL_DATABASE() { $host = "localhost"; #usually localhost $account = "<>"; # username for access. eg. root $password = "<>"; $db_name = "<>"; #name of database on the server that you want to connect. #global $db_type; #$db_type = 4.1; # MySQL version $DB_Server = mysql_connect($host, $account, $password) or die(mysql_error());# or die ("Cannot connect to a database. Please try again later"); $DB_Server = mysql_select_db($db_name, $DB_Server) or die("Cannot select the database. Please try again later."); return $DB_Server; } than you use a boolean value (the return value of mysql_select_db) as mysql-resource. you should return the return value of mysql_connect as mysql-resource. Link to comment https://forums.phpfreaks.com/topic/87706-solved-mysql_qyer-is-not-a-valid-mysql-resource/#findComment-448650 Share on other sites More sharing options...
PFMaBiSmAd Posted January 25, 2008 Share Posted January 25, 2008 In the following line of code, you are replacing the value in $DB_Server (which was the mysql_connect() link resource) with the true/false result of the mysql_select_db() function call. The mysql_select_db() returns a bool value. $DB_Server = mysql_select_db($db_name, $DB_Server) or die("Cannot select the database. Please try again later."); Link to comment https://forums.phpfreaks.com/topic/87706-solved-mysql_qyer-is-not-a-valid-mysql-resource/#findComment-448653 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.