Solved

Website files and database linking on different servers

Posted on 2013-05-14
11
289 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
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

As a database administrator, you may need to audit your table(s) to determine whether the data types are optimal for your real-world data needs.  This Article is intended to be a resource for such a task. Preface The other day, I was involved …
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…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

770 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