Andrea
Andrea

Reputation: 1057

connect to mysql database via php using non-localhost user

I have a user called 'test'@'111.11.11.111' (for example).

When i call

mysql_connect('localhost', //mysql is hosted locally (as far as php is concerned)
              'test', //user is test
              'password');//test's password

it automatically tries to login 'test'@'localhost'. Trying [email protected] for username results in [email protected]@localhost to try logging in.

Can I tell php or mysql to log in 'test'@'111.11.11.111'?

EDIT: The mysql server is hosted on localhost (from php's perspective). The IP of server hosting the mysql database is something other than 111.11.11.111. The user is logging into the mysql server from IP address 111.11.11.111

Upvotes: 0

Views: 349

Answers (3)

Nertim
Nertim

Reputation: 380

maybe I am misunderstanding the question, but why can't you just change connect statement to

mysql_connect('111.11.11.111','test','password');

??

Upvotes: 1

Brian Glaz
Brian Glaz

Reputation: 15696

Did you try using 111.11.11.111 in place of 'localhost'? that should generate [email protected]

Upvotes: 1

Clive
Clive

Reputation: 36955

I don't think so, the point of setting where a user can connect from on the MySQL server (in this case '111.11.11.111') is for security. PHP can't override that security as far as I know.

Upvotes: 0

Related Questions