Link to home
Start Free TrialLog in
Avatar of phillystyle123
phillystyle123Flag for United States of America

asked on

running mysql on godaddy server - can't connect to my db

MySQL and PHP are both running on my godaddy windows server. I've successfully installed the MySQL DB and I can run php on the server. HOWEVER when I try to connect a page to the MySQL db - no dice - this is what my connection file looks like:

<?php
# FileName="Connection_php_mysql.htm"
# Type="MYSQL"
# HTTP="true"
$hostname_mbb = "xxx.hostedresource.com";
$database_mbb = "xxxwebsitedb";
$username_mbb = "xxxwebsitedb";
$password_mbb = "xxxx";
$mbb = mysql_pconnect($hostname_mbb, $username_mbb, $password_mbb) or trigger_error(mysql_error(),E_USER_ERROR);
?>

and this is how i'm connecting:

<?php require_once('Connections/mbb.php'); ?>

now, i built this site on a linux server and have no problems with the connection or any other bugs -
ASKER CERTIFIED SOLUTION
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of phillystyle123

ASKER

This is what I had to do to get my MySQL connection to work on my godaddy Windows server:

1. I found this godaddy help article and created a test page with the connection info on the same page (not a separate file):

http://help.godaddy.com/topic/67/article/3351

2. After doing this, I got this error:

Client does not support authentication protocol requested by server; consider upgrading MySQL client

So, I logged on to phpMyAdmin and ran this command:
SET PASSWORD FOR user@localhost = OLD_PASSWORD('password');
The reasons for doing so can be found here:
http://geekswithblogs.net/TimH/archive/2005/10/31/58591.aspx

3. Then - since set up an external file originally to handle my connection - and it no longer worked when I migrated to godaddy - I made adjustments and this is what my external file looks like (that works with godaddy):

<?php
$hostname="xxx.hostedresource.com";
$username="myusername";
$password="mypassword";
$database_mbb="mydatabase";

$con = mysql_connect($hostname,$username, $password) or die ("<html><script language='JavaScript'>alert('Unable to connect to database! Please try again later.'),history.go(-1)</script></html>");
?>

4. then in my php file I put this at the top:

<?php require_once('Connections/con.php'); ?>
<?php
mysql_select_db($database_con, $con);





See my comment below for the full solution - but this code works to make the connection in godaddy - it just took me an extra step and then i created an external file
Interesting.  the only time I've seen that error message is when either the PHP MySQL driver or the MySQL server were really new versions that weren't compatible with an older one.  My program runs from the Godaddy server and from my own IIS5.0 server to connnect to the MySQL server on Godaddy.  I set my database up for external access.

The only real difference between my code and the code above is the 'die' part after the connect statement.  And I'm using 'mysql_pconnect' (persistent) where you're using 'mysql_connect'.