For Programmers: Free Programming Magazines  


Home > Archive > PHP Language > May 2006 > Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in
macca

2006-05-30, 7:57 am

Warning: mysql_query(): supplied argument is not a valid MySQL-Link
resource in/home/macca/public_html/somethingartistic/index.php on line
42

I am getting this message when i try to run my code on my hosts server
(using php 4) but it works fine on my own sysem (running php 5)

Example snippet:

<?php
include ("admin/config.php");
$query = "SELECT * FROM artists WHERE
category = 'Photography'";
$result = mysql_query($query, $connection);

$count = mysql_num_rows($result);
echo '<i>('.$count.' galleries)</i>';?>

Do you thisk it is the version that is causing the error or some error
of my own?

Cheers!

Rik

2006-05-30, 7:57 am

macca wrote:
> Warning: mysql_query(): supplied argument is not a valid MySQL-Link
> resource in/home/macca/public_html/somethingartistic/index.php on line
> 42
>
> I am getting this message when i try to run my code on my hosts server
> (using php 4) but it works fine on my own sysem (running php 5)


1. Is the database-connection established?
2. Does the table/field/category-value exist?

BTW: this is faster for this particular snippet:
$count = reset(mysql_query("SELECT COUNT(*) FROM artists WHERE category =
'Photography'"));

> Do you thisk it is the version that is causing the error or some error
> of my own?


In the posted snippet is nothing that would suggest a version problem. So
probably one of your own :-)

Grtz,
--
Rik Wasmus


macca

2006-05-31, 7:00 pm

Line 42 in this function is:

$result = mysql_query($query, $connection);


Surely

"not a valid MySQL-Link resource"

wouldnt mean:

cannot connect to the database would it? wouldnt it just print out
"cannot connect to database"?

all my config file has is:


<?php

$dbh=mysql_connect ("localhost", "<user>",
"<mypassword>") or die ('I cannot connect to the database because: ' .
mysql_error());
mysql_select_db ("<mydatabasename>");

return;
?>

I just noticed that the variable is $dbh and not $connection;

I changed the variable to $dbh due to the string my hosting provider
asked me to use for a database connection.

If a changed the connection variable to $dbh instead of $connection do
you think this might work?

macca

2006-05-31, 7:00 pm


OH WHAT A STUPID MISTAKE FOR ME TO MAKE !!!!!

Somethimes you can't see the forest through the trees!

I changed the connection var and all seems well !

:-)

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2009 codecomments.com