Hi I have encountered the following error:

Warning: mysql_connect() [function.mysql-connect]: Lost connection to MySQL server during query in

I don't know what is exactly the local host: shell I use only my domain or I need to use a special path...I would appreciate if somebody can help on this.

Thanks!

TW
-------------------------------------------
http://www.000webhost.com/?id=19415

Recommended Answers

All 10 Replies

Can you show us your code ?

Here it is

I have a daabase (my_db) and a user to it (any). The code goes:

$LOC= "localhost:3307";
$USER = "any";
$PASS = "xxxxxxx";
$DB = "my_db";

$con = mysql_connect($LOC,$USER,$PASS);
if (!$con){
 die('Could not connect: ' . mysql_error());
}
mysql_close($con);

it's the basic....I cannot even connect.

TW

------------------------------------------
http://www.000webhost.com/?id=19415

Thats because, you have mysql_close($con) in your code. You should use mysql_close only after you have performed whatever operation you want to do with the database. I would use something like this.

function open_connection(){
 $host='localhost';
$user='user';
$db='dbname';
$password='pass';
$conn=mysql_connect($host,$user,$password);
mysql_select_db($db);
return $conn;
}
function close_connection($conn){
mysql_close($conn);
}

So, whenever I have something to do with the database, I call the function open_connection().
$connection=open_connection();
....sql statements.....
Then close it using
close_connection($connection);

Cheers,
Naveen

What are you trying to achieve ? Is this all the code you have ? Try a simple example.

<?php
$conn=mysql_connect("hostname","username","password");
mysql_select_db("dbname");
$query="select * from tablename";
$result=mysql_query($query);
while($row=mysql_fetch_array($result)){
  print_r($row);
}
?>

Execute the above code and tellme if you find any errors.
P.S. Change username, localhost, password, dbname, tablename according to your needs.

I'm getting the same error:

Warning: mysql_connect() [function.mysql-connect]: Lost connection to MySQL server during query

and the other from the querry....

I am tryng to connect to my database. Then I can start inserting data...

Seems I've hit the grain

TW
----------------------------
http://www.000webhost.com/?id=19415

Ok ! Instead of mysql_connect, try connecting using mysql_pconnect . If that doesn't fix your problem, also try using the port number in your hostname. For example, instead of localhost, try localhost:3306 . Make sure that port 3306 is not blocked by your firewall.

I did tried it the mysql_pconnect() results in the sam effect...


3306 isn't working as well. I found it is a server issue not coding...so I need to see how to establish a connection with my database...

Your connection to mysql is getting reset everytime. Lets see if someone has an answer for this.

000webhost free account "Remote MYSQL connections are disabled" so if you'd like to connect to mysql pay first :> i think that was the sollutions

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.