Error -> Connect to remote MySqlDatabase

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

asterinex
Forum Commoner
Posts: 52
Joined: Thu Nov 25, 2004 7:01 am
Location: Belgium

Error -> Connect to remote MySqlDatabase

Post by asterinex »

Hello,

I have a Mysql Database at a server with a lot of data in it.
Now I have another domain, but I want to access de DB at my other site to read the data. So I replaced Localhost with mydomain.


I used this line of code

$ie_conn = mysql_connect("www.mydomain.com", "user","Password");

The Error

Warning: Access denied for user: 'user@d31A4C67E.kabel.telenet.be'

Anyone Knows a solution ?


Thanks
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

Post by kettle_drum »

Make sure that the user is allowed to login from a remote location - check the Host column in the User table in the mysql database. If it says 'localhost' then you need to change it to either % or the IP address of the second server. You might also want to just create a new user that is only allowed from the second server's IP and give it limited privledges.
asterinex
Forum Commoner
Posts: 52
Joined: Thu Nov 25, 2004 7:01 am
Location: Belgium

Post by asterinex »

Thanks, but I cannot change Localhost on my Server . The Actual Idea is to write a small game in c++ that connects to the database to update Highscores ,......
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

you could put a little script on yoru server that accepts sql queries or so... and then call that script from whatever program that needs it..
asterinex
Forum Commoner
Posts: 52
Joined: Thu Nov 25, 2004 7:01 am
Location: Belgium

Post by asterinex »

Thanks, Could you tell me a bit more about scripts.? What language is it ? Maybe you have an exemple or know a good site to find that info?
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

Post by kettle_drum »

Just a PHP script that takes a query as input, and then returns the results.

Code: Select all

if($_POST['uid']=='jkhsafib3d7'){    //do some kind of user check/login
   $query = check_query($_POST['query']);
   $result = mysql_query($query);
   //print the results back to the user
}
asterinex
Forum Commoner
Posts: 52
Joined: Thu Nov 25, 2004 7:01 am
Location: Belgium

Post by asterinex »

Thanks
Last edited by asterinex on Sun Dec 05, 2004 11:17 am, edited 1 time in total.
asterinex
Forum Commoner
Posts: 52
Joined: Thu Nov 25, 2004 7:01 am
Location: Belgium

Post by asterinex »

Thanks, But I need a communication between a client game c++ en mysql on the server in both ways.

Sending Query -> Updating records.
Receiving Result of Query -> Who´s online , or who is the best Highscore.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

just plug libcurl into your c++ app.. and do your thing..... (or try to find a mysql server that allows external connections)
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

If you know C++ then PHP will be easy for you. Write some C++ code that posts data to a url on your server. Use a php script to update the database, and then return data back to your application in for form of an ini file or something.

Code: Select all

їwhos_online]
username
username2
username3

їhighestscores]
25112254
15224456
etc....
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

adodb package has a script.... server.php that does exactly this: accept query through get parameter, and then return resultset packaged as CSV string/file

or you are into xmlslow, have a look at soap etc :p
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

Post by kettle_drum »

Just as a note: the little bit of code i wrote above does allow communication both way - to get results and insert data.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

You don't want your app remotely connecting to the database anyway, then anyone with a packet sniffer will have the username and password and could wreak havoc on it or create invalid entries, such as impossible high scores.
asterinex
Forum Commoner
Posts: 52
Joined: Thu Nov 25, 2004 7:01 am
Location: Belgium

Post by asterinex »

Thnanks,

So the best thing to do is to use POST & GET. Is also fast & stable enough to query with 500 users every minute ? and is it possible to retrieve Text fields of +- 256 Chars ?
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

agtlewis wrote:You don't want your app remotely connecting to the database anyway, then anyone with a packet sniffer will have the username and password and could wreak havoc on it or create invalid entries, such as impossible high scores.
nobody said you have to do it unencrypted :P

both, methods (mysql lib and http - php proxy) can use SSL :)
invalid entries can always be made, it's just a matter on how hard you want to make it not to happen....
Post Reply