Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

MacDonaldsd

macrumors 65816
Original poster
Sep 8, 2005
1,005
0
London , UK
Im having a problem with connecting to my mySQL database via PHP. I modified GoDaddy sample PHP script:

<?php
//Sample Database Connection Syntax for PHP and MySQL.

//Connect To Database
$hostname="mysqladmin2.secureserver.net";
$username="anotherdatabase";
$password="*****";
$dbname="anotherdatabase";
$usertable="music";
$yourfield = "artist";



mysql_connect($hostname,$username,$password);
mysql_select_db($dbname);

# Check If Record Exists

$query = "SELECT * FROM $usertable";

$result = mysql_query($query);

if($result)
{
while($row = mysql_fetch_array($result))
{
$name = $row["$yourfield"];
echo "Name: ".$name."
";
}
}
?>


And I get the error

Warning: mysql_connect(): Lost connection to MySQL server during query in (the URL) on line 15

Which is: mysql_connect($hostname,$username,$password);
 
If you're not receiving any errors when you connect, then it looks like the connection is happening perfectly fine.

If you're losing connection during the query, it almost sounds like it's a problem with your MySQL server provider. You might contact them and see if they can help you.
 
Is your Mysql DB hosted at godaddy? i use them for one of my servers, and i tried to use a mysql db at a different host, i couldn't get it to work right, so i ended up moving the db to godaddy
 
The problem was with the $hostname they gave me a different one to use.

On a side note it won't work with the mysqli function at all.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.