Strange PHP/mySQL error ... am I just tired?

Posted on 16th Feb 2014 by admin

Code: <?

## CONNECT TO DB FUNCTION!
function ConnectTo($db2con)
{
$hostName = "localhost";
$dbName = "people_".$db2con;
$userName = "people_main";
$password = "normal123";
$link = mysql_connect($hostName, $userName, $password) or die("Unable to connect to host $hostName");
mysql_select_db($dbName, $link) or die( "Unable to select database $dbName");
return $link;
}

$conn = ConnectTo("estore");

$query = "SELECT * FROM CubeCart_inventory";
$result = mysql_query($query) or die(mysql_error());

$num = mysql_num_rows($result);

while ($row=mysql_fetch_array($result)) {

$prod = $row['productId'];
$cat = $row['categories'];

}

?>

I have the above code ... EVERYTIME it runs I get this error:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/people/public_html/code/xml/scripts/loadCatIDx.php

I do not understand this problem! I understand the error is implying my query returned an error, however when I add echo mysql_num_rows($result) it returns over 2700 records ...

Any help would be greatly appreciated!!

Other forums