Access MySQL database problem!
Posted: Wed Feb 02, 2011 3:36 pm
Hi. I am getting crazy here, I would be very pleased if any of you can help me with this problem. Here is the thing...
The following code works perfectly:
However when I try to use a function for the query and the rest, I have a problem there.. For instance, when I try this:
I face with the following problem:
Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in *****/index.php on line 42
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in ******/index.php on line 43
then I tried to change the code a bit to check where the problem is:
after this it returned "sth wrong". So, i guess i m having a database connection problem while i try to use mysql_query in the function.
Thank you very much for your suggestions...
--
Pasha Latzo
The following code works perfectly:
Code: Select all
$user_name = "*****"; // replace your user name within the 2x "
$password = "*****"; // replace your password within the 2x "
$database_name = "*****"; // replace the database name within the 2x "
$table_name = "*****"; // replace the table name within the 2x "
$dbh = mysql_connect("*****", $user_name, $password, $database_name);
$query="SELECT streamLink FROM `$database_name`.`$table_name` WHERE streamName = 'Sands'";
$result = mysql_query($query, $dbh);
$num=mysql_num_rows($result);
echo ($num);
Code: Select all
$user_name = "*****"; // replace your user name within the 2x "
$password = "*****"; // replace your password within the 2x "
$database_name = "*****"; // replace the database name within the 2x "
$table_name = "*****"; // replace the table name within the 2x "
$dbh = mysql_connect("*****", $user_name, $password, $database_name);
function findStreamLink($stream_name)
{
$query="SELECT streamLink FROM `$database_name`.`$table_name` WHERE streamName = '$stream_name' ";
$result = mysql_query($query, $dbh);
$num=mysql_num_rows($result);
echo ($num);
}
Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in *****/index.php on line 42
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in ******/index.php on line 43
then I tried to change the code a bit to check where the problem is:
Code: Select all
$user_name = "*****"; // replace your user name within the 2x "
$password = "*****"; // replace your password within the 2x "
$database_name = "*****"; // replace the database name within the 2x "
$table_name = "*****"; // replace the table name within the 2x "
$dbh = mysql_connect("*****", $user_name, $password, $database_name);
function findStreamLink($stream_name)
{
if(!$dbh)
{
echo('sth wrong');
}
else
{
$query="SELECT streamLink FROM `$database_name`.`$table_name` WHERE streamName = '$stream_name' ";
$result = mysql_query($query, $dbh);
$num=mysql_num_rows($result);
echo ($num);
}
}
Thank you very much for your suggestions...
--
Pasha Latzo