Forum Moderators: open

Message Too Old, No Replies

Loosing Connection

I am loosing my connection...

         

Programmers

4:15 am on May 17, 2007 (gmt 0)

10+ Year Member



I am a bit of a noob to SQL and I am trying to show a product database. I've entered the following to display a list of products by using PHP.

$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.

mcibor

7:23 am on May 18, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Here you've got the most common reasons why this may happen:

[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

IndiaMaster

12:01 pm on May 26, 2007 (gmt 0)

10+ Year Member



Hi,

Your syntax is correct as far as I see. But is there any time limit or you get the error message instantly?

Programmers

10:35 am on Jun 13, 2007 (gmt 0)

10+ Year Member



@mcibor - Thank you. I will take a look at those links ASAP.

@IndiaMaster - I get it instantly. My results display, but I get that error message above them.