PDA

View Full Version : Connecting to a database on a different server...


HBeta
07.15.06, 03:57 PM
Hello,

I have a question for you code-gurus around here...

I have a website called VernalHost.com. I am about to begin production on a script that is going to require license verification before the user is able to use the script. What I want to do is create a MySQL database on the VernalHost.com server, and then let that database hold all of the license information, such as the username, script name, license number, domain the script can be used on, ip address for the server, etc.

Then, what I want in the script is something like a file called license.php that no matter what server it's installed on, it will connect to the VernalHost.com MySQL database and check a couple of different parameters, such as the license number, the domain it's trying to be installed on, etc.

So, say that someone on the google.com server wanted to use my script. They'd go through google.com/script/install.php to install it, enter their license, etc.

Then, say they tried to access google.com/script/index2.php ... The index2.php file will hold the require("license.php"); tag, that way everytime they try to access a part of the script, it always connects to the VernalHost database to verify the license.

Does this all make sense?

If so, what would be the code snippet to connect to the database across different servers?

Thanks to you all for the help...
Ricky

Koobi
07.16.06, 01:11 AM
I moved this from General Webcoding to PHP/MySQL because it's PHP & MySQL specific.

to connect to mysql, you can use either mysql_connect (the most common method) or mysql_pconnect (for persistent connections).
Whichever you use, you simple have to enter your host as the server parameter.

eg:

<?php
mysql_connect('vernalhost.com', 'myUser', 'myPass');
?>

HBeta
07.16.06, 01:16 AM
Oh okay. See, I knew about the mysql_connect function, I just didn't know i could use vernalhost.com instead of localhost.

That's easy enough...Thank you. =)

kvack
07.16.06, 03:38 AM
just gota make sure your mysql database sets up the table access for external IPs.

Koobi
07.16.06, 04:26 AM
but MySQL handles permissions based on users right? or does it handle permissions based on the host as well?

HBeta
07.16.06, 10:26 PM
Well, if you're using cPanel, you can go into the MySQL administrator and there is a place called "Access Hosts." If you enter a single wildcard (%) then it will accept all connections from any website using 'yourdomain.com' as the connection target. Then, use the correct username/password you setup, and set that user to which database it can access, and there you have it, any website on the outside with that username/password can access that database.

kvack
07.17.06, 05:43 AM
but MySQL handles permissions based on users right? or does it handle permissions based on the host as well?

Table rights grant access to users at locations...

Koobi
08.27.06, 05:19 AM
Table rights grant access to users at locations...


ooops missed this post.

how do you mean by that though?
i thought mysql just handles permission for a use per table and the web server settings handles external access. wouldn't make sense otherwise.

basic mind
01.17.07, 06:56 AM
if the mysql is not setup for external connections it wont allow you to access the db. I know with the 1&1 hosting stuff you cant connect to the db unless its running from your own space.