/    Sign up×
Community /Pin to ProfileBookmark

issue connecting to remote mysql

hi all guys.
i have a mamp installed on my mac with leopard and a domain name ready, i’m having some issue connecting to remote server via php script, what i’m using is:

[code=php]
$host= “77.75.???.??”; (masked by??? and no port specified at the end)

$user= “user”; (correct and doublechecked)

$pass= “pass”; (correct and doublechecked)

$conn= mysql_connect($host,$user,$pass);
//a die() follows in case of no connection
[/code]

but it gives me always error: Can’t connect to MySQL server on ‘77.75.???.?? (4)

any advice?

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@sneakyimpFeb 26.2009 — I'm assuming that your ? chars are actually numbers of some real IP address.

You need to check for error conditions when you try to connect:
[code=php]
$conn= mysql_connect($host,$user,$pass)
or die(mysql_error());
[/code]


Hopefully that will give you a bit more information. The failure could be due to a number of things:

1) MySQL server is not listening on the default port in which case you should specify a port

2) user/pass doesn't have permission to connect from a remote machine -- you'll need to add the proper permissions to the db

3) the address is wrong, etc.
Copy linkTweet thisAlerts:
@jsfreakauthorMar 01.2009 — i discovered, my server client simply does not allow remote connections/
Copy linkTweet thisAlerts:
@zahidrafMar 02.2009 — That's fine

but you can ask your hosting company if you have dedicated server to open port to acess the remmote database.

One Button Controller
Copy linkTweet thisAlerts:
@MindzaiMar 02.2009 — i discovered, my server client simply does not allow remote connections/[/QUOTE]

I'm not sure if your particular situation, but if MySQL is not allowing remote connections it will just be a configuration issue - perhaps you are trying to connect using an account specified as localhost only? Or maybe your server is behind a router and port 3306 needs forwarding?
Copy linkTweet thisAlerts:
@jsfreakauthorMar 02.2009 — Hi MindZai

actually i was simply trying to connect from a script on my machine and it did not work, throwing me out with a connection error message,

I've contacted the hosting provider and they've told me that remote connection its not allowed for security reasons and that i should upload the php scripts with "localhost" host-name.

Cheers
Copy linkTweet thisAlerts:
@SyCoMar 02.2009 — MAMP, LAMP and WAMP are great for offline developing but there are a few thing to watch for, this being one of them. You can rebuild the databases locally and still use MAMP and sync the files to your host when you're done and if you use the same info you won't even need to change your connect statement.

This command is use to examine the table structure
[CODE]show create table;[/CODE]

and from a shell (not the mysql> prompt) this is handy for transferring a database (all tables).

[CODE]$mysqldump -u username -ppassword databasename > /path/to/textfile.txt
[/CODE]

(you can just use mysql if mysqldump gives you problems)

This will create a text file to entirely copy the tables and contents. Just copy it to your local machine, change the path to the text file, change the direction of the arrow and it''ll upload to you local machine database.

[CODE]$mysql -u username -ppassword databasename < /new/local/path/to/textfile.txt[/CODE]

The other thing that snags a lot of people is the php ini file. echo phpinfo(); on the host machine and you MAMP box and compare the configurations. Just make sure there are no major differences or missing mods that you'll be relying on and the settings such as error_reporting are the same.
×

Success!

Help @jsfreak spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.13,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...