Solved

Website files and database linking on different servers

Posted on 2013-05-14
11
282 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 82

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 42

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 108

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
 

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 108

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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 82

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 42

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 82

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 108

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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Creating and Managing Databases with phpMyAdmin in cPanel.
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

708 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now