Jump to content

[SOLVED] mysql_qyer() is not a valid MySQL resource


PC Nerd

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.