03-06-13, 21:00 #1Registered User
- Join Date
- Oct 2012
Unanswered: Godaddy database connection error ...
I am having a bigg problem and I am completely at loss here ..
I am trying to connect to the godaddy database (MYSQL Database)
I have worked with the code on my local machine n it was working perfectly. But on the website the database connection just isnt happenening ..
Please help me sumone ..
My code is:
$hostname = "host";
$username = "user";
$dbname = "db";
$password = "pass";
$usertable = "table";
mysql_connect($hostname, $username, $password);
$query = "SELECT * FROM $usertable";
$result = mysql_query($query);
while($row = mysql_fetch_array($result))
echo "loginid: " . $row["loginid"];
03-07-13, 03:37 #2Jaded Developer
Provided Answers: 59
- Join Date
- Nov 2004
- out on a limb
consider using the or die statement to find out what errors are being reported
you should really be using a different mechanism to connect to the DB, try mysqli. mysql was deprecated years ago and as such is not guaranteed to be available in the future
in the above reference you will see two metholds
mysqli::$errno — Returns the error code for the most recent function call
mysqli::$error — Returns a string description of the last error
which will tell you why the MySQL isn't working.
http://www.dbforums.com/php/1666803-...mp-server.htmlI'd rather be riding on the Tiger 800 or the Norton
03-13-13, 15:21 #3Registered User
- Join Date
- Sep 2009
- San Sebastian, Spain
healdem is right. You really need to test the results of your functions and to display the error messages. If mysql_connect fails you continue to call the next function. When your process completes you will not know where your error actually occurred. You may end up thinking that it was the SQL statement that failed when it could have been the connection.
Also mysql, though it has been deprecated, is still supported but again you should have a look at migrating away from this. An alternative to mysqli is PDO which allows you to eventually change the database driver without having to change your code. This way your code can work on MySQL, PostgreSQL, SQL Server, Oracle without any changes (that's the theory, the practice is that there is always something that would need to be changed but these would be minimal).