Forum Moderators: open
$server = mysql_connect("####", "####", "####");
$dbh=mysql_connect ("localhost", "###", "###") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("####");
$sql = "SELECT id, name, description, price, stock, count FROM products";
$result = mysql_query($sql);
while($row = mysql_fetch_array($result))
{
print $row["id"]." - ".$row["name"]." - ".$row["description"]." - £".$row["price"]." - ".$row["stock"]." - ".$row["count"]."<BR>";
}
The code does work, as under the error message I see the rows of data. However, the error message shouldn't be there, but I don't understand it:
Warning: mysql_connect() [function.mysql-connect]: Lost connection to MySQL server during query in /home/#####/public_html/#####/gen.php on line 6
Could someone help me please,
thanks in advance,
Tom.
[dev.mysql.com...]
PS. Don't you want to limit the query in any way?
$sql = "SELECT id, name, description, price, stock, count FROM products LIMIT 30";
$result = mysql_query($sql) or die("SQL: $sql ".mysql_error());
more on LIMIT:
[dev.mysql.com...]
[php.about.com...]
Hope these links will help you
Michal