GoDaddy mySQL/PHP Problem

MacDonaldsd

macrumors 65816
Original poster
Sep 8, 2005
1,009
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);
 

Winterfell

macrumors regular
Apr 3, 2007
151
0
Tulsa, Oklahoma
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.
 

X1Lightning

macrumors 6502
Feb 19, 2007
413
0
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
 

MacDonaldsd

macrumors 65816
Original poster
Sep 8, 2005
1,009
0
London , UK
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.