sd9sd Posted July 10, 2008 Share Posted July 10, 2008 Done a lot of googling but the solutions didn't work. Thought I'd post it in a way which would help others as well as me. I'm using fictitious passwords and domain names, so let these not be confused with any constants. I'm working on a website called www.something.com My SQL database is on a domain called www.nothing.com I've logged into www.nothing.com with the username 'sam' and password 'abc'. I created a database named 'icecream'. In this database I created a table named 'tags'. I've got a PHP file which I'm running from www.something.com as http://www.something.com/testing.php This is the code I'm using to connect to the icecream database. $host="ftp.nothing.com"; $user="sam"; $password="abc"; $conn = @ftp_connect("$host"); if (!$conn) {echo("&result=0&");echo 'Error: Could not connect to ftp server';ftp_close($conn);exit;} $result = @ftp_login($conn, $user, $password); if (!$result) {echo("&result=0&");echo "Error: Could not log on as $user";ftp_quit($conn);exit;} $DB_SERVER="www.nothing.com"; $DB_USER="sam_owner"; $DB_PASS="abc"; $DB_NAME="sam_tags"; define("TBL_USERS", "icecream"); $connection = @mysql_connect($DB_SERVER, $DB_USER, $DB_PASS); if (!$connection) {echo "SQL error. Tag names couldn't be obtained";} $sc = @mysql_select_db($DB_NAME, $connection); I'm able to login to the nothing.com website but can't connect to the database. Could anyone be kind enough to tell me where I've gone wrong? Quote Link to comment https://forums.phpfreaks.com/topic/114036-solved-mysql_connect-connecting-to-database-on-another-server/ Share on other sites More sharing options...
Lamez Posted July 10, 2008 Share Posted July 10, 2008 the database has to be set to allow remote users to logon. I suggest you do it all local, it much safer. Quote Link to comment https://forums.phpfreaks.com/topic/114036-solved-mysql_connect-connecting-to-database-on-another-server/#findComment-586123 Share on other sites More sharing options...
DarkWater Posted July 10, 2008 Share Posted July 10, 2008 I'm pretty sure the database isn't on http://www.nothing.com, check the IP of the phpMyAdmin that you use to access it. Also, some web hosts only allow access to databases from the domains that they're created under (GoDaddy does this). Quote Link to comment https://forums.phpfreaks.com/topic/114036-solved-mysql_connect-connecting-to-database-on-another-server/#findComment-586124 Share on other sites More sharing options...
Lamez Posted July 10, 2008 Share Posted July 10, 2008 ya, Servage lets me do remote or local, and they give me a special subdomain like: mysql_155.servage.com Quote Link to comment https://forums.phpfreaks.com/topic/114036-solved-mysql_connect-connecting-to-database-on-another-server/#findComment-586125 Share on other sites More sharing options...
Bendude14 Posted July 10, 2008 Share Posted July 10, 2008 what error messages are you getting... I have connected to a remote database like this before and it worked fine but i did use the ip address. If you are running this script on your website www.something.com you do not need the ftp section at the top to connect to www.nothing.com or is this just a test for the username and password? Make sure that the username and password for the DB are correct. As i understand it you are using the same username and password for the ftp to this server as for the database.. Hope this helps Quote Link to comment https://forums.phpfreaks.com/topic/114036-solved-mysql_connect-connecting-to-database-on-another-server/#findComment-586134 Share on other sites More sharing options...
sd9sd Posted July 10, 2008 Author Share Posted July 10, 2008 Thanks lamez and DarkWater....I had an email conversation with the domain host (nettigritty). They say that they've disabled remote SQL access for the past five years due to security reasons. It's necessary for me to access it remotely coz both sites access the same database. I've been thinking of alternate options and one option seems to be to have a php file in www.nothing.com, which access the database and sends the info to the php file which calls it. The calling php will be in www.something.com. @Bendude: the error was suppressed with the @, but the main point is that I've used the exact same code for connecting to the database using localhost (while I was working on www.nothing.com). So the names are correct...I'm sure of it. Thanks for mentioning that logging in to the website isn't necessary...that helped. Quote Link to comment https://forums.phpfreaks.com/topic/114036-solved-mysql_connect-connecting-to-database-on-another-server/#findComment-586148 Share on other sites More sharing options...
Bendude14 Posted July 10, 2008 Share Posted July 10, 2008 yes i can see that you were supressing the error messages but i just thought that might help locate the problem.. if you retrieved the information with a php file on the same server as the database you could include that php file onto your other server using server side include. I think some hosting companies disable including remote files also though for security Quote Link to comment https://forums.phpfreaks.com/topic/114036-solved-mysql_connect-connecting-to-database-on-another-server/#findComment-586152 Share on other sites More sharing options...
sd9sd Posted July 10, 2008 Author Share Posted July 10, 2008 Thanks Bendude14....I tried including it like this... This is the caller.php file on www.something.com <?php include("http://www.nothing.com/called.php"); $id=$_POST["id"]; echo "id value is =$id"; $id=$_GET["id"];//so that it'd receive the value either by get or post echo "id value is =$id"; ?> and this is the code in called.php <?php echo "yay"; ?> But it gives an error saying: Warning: include() [function.include]: URL file-access is disabled in the server configuration in /home/LOGINNAME/public_html/caller.php on line 2 Warning: include(http://www.nothing.com/called.php) [function.include]: failed to open stream: no suitable wrapper could be found in /home/LOGINNAME/public_html/caller.php on line 2 Warning: include() [function.include]: Failed opening 'http://www.nothing.com/called.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/LOGINNAME/public_html/caller.php on line 2 id value is =id value is = I'm still only starting to understand how to use php code, so please bear with me...how is this include supposed to be done? Quote Link to comment https://forums.phpfreaks.com/topic/114036-solved-mysql_connect-connecting-to-database-on-another-server/#findComment-586159 Share on other sites More sharing options...
sd9sd Posted July 10, 2008 Author Share Posted July 10, 2008 I hoped the "yay" word would be captured by the GET or POST...but something tells me that it wouldn't work like that... Quote Link to comment https://forums.phpfreaks.com/topic/114036-solved-mysql_connect-connecting-to-database-on-another-server/#findComment-586162 Share on other sites More sharing options...
Bendude14 Posted July 10, 2008 Share Posted July 10, 2008 well your syntax for the include is correct and looking at the error message it looks as though the server does not allow you to include files from other servers Quote Link to comment https://forums.phpfreaks.com/topic/114036-solved-mysql_connect-connecting-to-database-on-another-server/#findComment-586164 Share on other sites More sharing options...
sd9sd Posted July 10, 2008 Author Share Posted July 10, 2008 Darn! isn't there ANY way to access the database then? I hoped that php would have a function like send_query("www.nothing.com/called.php?id=1"); But they haven't provided any such function either. Any ideas please? I need both websites to access the same database. Quote Link to comment https://forums.phpfreaks.com/topic/114036-solved-mysql_connect-connecting-to-database-on-another-server/#findComment-586167 Share on other sites More sharing options...
Bendude14 Posted July 10, 2008 Share Posted July 10, 2008 I dont no of any other way to do it. Maybe you could get a third server just for the database that allows remote sql logins and they could both connect to it that way. Someone else might come up with another idea though. Quote Link to comment https://forums.phpfreaks.com/topic/114036-solved-mysql_connect-connecting-to-database-on-another-server/#findComment-586171 Share on other sites More sharing options...
sd9sd Posted July 10, 2008 Author Share Posted July 10, 2008 Help please!!! Quote Link to comment https://forums.phpfreaks.com/topic/114036-solved-mysql_connect-connecting-to-database-on-another-server/#findComment-586176 Share on other sites More sharing options...
sd9sd Posted July 11, 2008 Author Share Posted July 11, 2008 if your host provider doesn't allow remote access, one option is to move the remote domain onto the same server as the local domain. This way, you'll be able to access the database from both sites as localhost. Quote Link to comment https://forums.phpfreaks.com/topic/114036-solved-mysql_connect-connecting-to-database-on-another-server/#findComment-587240 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.