Solved

Website files and database linking on different servers

Posted on 2013-05-14
11
295 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
[X]
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
  • 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 110

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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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 110

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 110

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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.

749 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