Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Website files and database linking on different servers

Posted on 2013-05-14
11
292 Views
Last Modified: 2013-06-06
I have a website all set up and working using MySQL.

My client now want the website hosted on their own servers. However it's a bit of a game to get database's set up there so I want to keep the database on my server but move the website files to his server.

Until now I have only ever connected a website with a database on the same server using the Dreamweaver created connection script like this...

# FileName="Connection_php_mysql.htm"
# Type="MYSQL"
# HTTP="true"
$hostname_iafl = "localhost";
$database_iafl = "database";
$username_iafl = "username";
$password_iafl = "password";
$iafl = mysql_pconnect($hostname_iafl, $username_iafl, $password_iafl) or trigger_error(mysql_error(),E_USER_ERROR); 

Open in new window



How would I edit this to link to another server? I have tried changing 'localhost' to the ip address but that didn't work?
0
Comment
Question by:BrighteyesDesign
  • 3
  • 3
  • 3
  • +1
11 Comments
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 39165876
Allow incoming connections in your firewall for port 3306.  You also have to make sure that the user is allowed to connect remotely.  It is common practice to create the user twice with the same password but different connections, 'localhost' and '%' (anyhost).  If you have phpMyAdmin on your machine, this is very easy.  You can copy a user and just change the connection.

http://dev.mysql.com/doc/refman/5.1/en/adding-users.html
0
 
LVL 43

Expert Comment

by:Chris Stanyon
ID: 39165924
You'll also need to change the hostname to your IP address, as it won't be localhost any more!

$hostname_iafl = "123.456.789.012";
0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 39168047
This is only tangentially related, but you'll also need to get off of MySQL because PHP is removing support for the MySQL extension. This article tells what you must do and why.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/PHP_Databases/A_11177-PHP-MySQL-Deprecated-as-of-PHP-5-5-0.html

Best to all, ~Ray
0
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 

Author Comment

by:BrighteyesDesign
ID: 39168183
ffs, so i'm stressing here with timescales and paying the bills and I now have to change 85 websites so the support MySQLi?

I guess all will be ok until my hosts decide to intall the latest PHP?

Thanks for the heads up though Ray...
0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 39168279
You'll probably get DEPRECATED messages before everything falls apart.  But if you're not expecting the messages, it can get nasty - especially if you use cookies or other headers.
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 39168898
I have had to do 'emergency repairs' on a couple of websites because the host upgraded PHP.  The move from PHP 4.4 to PHP 5.3 can break a lot of things.  It caused so much trouble that the host backed down to PHP 5.2 which was much more compatible with the old code.
0
 

Author Comment

by:BrighteyesDesign
ID: 39168918
I've been crying in a corner since I discovered this.

So much work to do it's incredible. And what about templated carts like Prestashop? I have a couple of sites using that and wouldn't have a clue how to alter that code.

Guessing there's going to be a lot of posts on this site along the lines of.."how do I change this MySQL code to MySQLi"!
0
 
LVL 43

Accepted Solution

by:
Chris Stanyon earned 167 total points
ID: 39168989
I wouldn't overly stress about this - these things don't usually happen over night - it often takes years between an announcement of deprecation and a flat out non-supported fatal error!! All of the big players such as Prestashop etc should be updating their core code to ensure it's suitable - if not, they won't keep their customer base for very long.

If you're overly concerned, talk to your host and ask what their timescale is for updating PHP.

Bear in mind that the mysql extenstion will be deprecated from PHP 5.5, and probably won't be removed until 5.6 or 5.7 - we're only on 5.4 at the moment so technically it's not even deprecated yet.

You should definitely be using mysqli or PDO for any new code that you write, but I certainly wouldn't start panicking over old sites just yet :)
0
 

Author Comment

by:BrighteyesDesign
ID: 39169007
Thanks for that Chris, i'll get stuck into mysqli and should know my way around it by the time it stops for good!
0
 
LVL 83

Assisted Solution

by:Dave Baldwin
Dave Baldwin earned 167 total points
ID: 39169030
I agree with Chris.  A more immediate problem on upgraded versions of PHP can be $HTTP_COOKIE_VARS, $HTTP_POST_VARS and $HTTP_GET_VARS which caused almost all the problems in the site I had to rescue.  The 'mysql' code worked fine.
0
 
LVL 109

Assisted Solution

by:Ray Paseur
Ray Paseur earned 166 total points
ID: 39169933
I agree with Chris, too.  It's not a bus hurtling toward you, it's more of a problem that can be handled in your spare time.  But it will have to be handled eventually.  In my experience the easiest MySQL change has been to move from MySQL to MySQLi in the object-oriented format.  The procedural format will require you to change all of your query statements because the argument order is reversed (what was PHP thinking when they did that??)
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
MySQL Sub-Select Query Returning Duplicate Result 7 45
Split wordpress loop 35 56
PHP and JQuery Syntax question 4 26
PHP Mail error 3 26
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question