user315845
user315845

Reputation: 21

Connecting to external MySQL DB from a web server not running MySQL

While I've been working with MySQL for years, this is the first time I've run across this very newbie-esq issue. Due to a client demand, I must host their website files (PHP) on a IIS server that is not running MySQL (instead, they are running MSSQL). However, I have developed the site using a MySQL database which is located on an external host (Rackspace Cloud). Obviously, my mysql_connect function is now bombing because MySQL is not running on localhost.

Question: Is it even possible to hit an external MySQL database if localhost is not running MySQL?

Apologies for the rookie question, and many thanks in advance.

* To clarify, I know how to connect to a remote MySQL server, but it is the fact that my IIS web server is not running ANY form of MySQL (neither server nor client) that is giving me trouble. Put another way, phpinfo() does not return anything about MySQL. *

Upvotes: 2

Views: 1764

Answers (4)

Marc B
Marc B

Reputation: 360732

The MySQL server has nothing to do with PHP itself. What "mysql support" in PHP means is that it's been compiled with (or has a module loaded) that implements the MySQL client interface. For windows, it'd be 'mysql.dll', and on Unix-ish systems it'd be 'mysql.so'. Once those are loaded, then the various MySQL intefaces (mysql_xxx(), mysqli_xxx(), PDO, MDB2, etc...) will be able to access any MySQL server anywhere, as long as you have the proper connection string.

Upvotes: 0

Ty W
Ty W

Reputation: 6814

you will need to install the mysql extensions. this link should help: http://php.net/manual/en/install.windows.extensions.php

Upvotes: 0

MindStalker
MindStalker

Reputation: 14864

If phpinfo is not returning anything about MySQL you need to install the MySQL plugin for PHP, easiest way to do that probably is to just upgrade PHP to the latest version. If not there is a .DLL file that you will need.

http://www.php.net/manual/en/mysql.installation.php

Upvotes: 0

Pascal MARTIN
Pascal MARTIN

Reputation: 401032

Yes, you can use a MySQL database that's not on the same machine as Apache+PHP.

Basically, you'll connect from PHP to MySQL via a network connection -- TCP-based, I suppose ; which means :

  • MySQL must be configured to listen to, and accept connections on the network interface
    • Which means configuring MySQL to do that
    • And given the required privileges to your MySQL user, so he can connect from a remote server
  • And PHP must be able to connect to the server hosting MySQL.

Note, though, that habing MySQL on a server that's far away might not be great for performances : each SQL query will have to go through the network, and this could take some time...

Upvotes: 3

Related Questions