Access MySQL via Virtual Hosts

You can ask general questions about MAMP here.

Moderator: severin

Post Reply
epferrari
Posts: 1
Joined: Fri 28. Mar 2014, 20:03

Access MySQL via Virtual Hosts

Post by epferrari » Fri 28. Mar 2014, 20:28

Hello,

Quick question: I'm developing several sites concurrently, so I use virtual hosts and keep them in a separate directory than htdocs so that the relative paths and includes work.

My sites are database driven, and I'd like to test using the populated content from the databases. I'm able to do that using the connection params in Webstart (host, user, and password). My php script is the standard:

Code: Select all

$host = 'localhost';
$user = 'root';
$pass = 'mampPassword';
$db = 'myDatabase';

$con = mysql_connect($host,$user,$pass);
if (!$con) {echo 'could not connect to server, '.mysql_error();}

$access = mysql_select_db($db);
if (!$access) {echo 'could not connect to database, '.mysql_error();}
else {echo 'Connected Successfully! You're awesome at life!';}
HOWEVER...

Code: Select all

$user = 'root' and $pass = 'mampPassword' 
are not the same for my production environment. Let's say they're

Code: Select all

$user = 'prodUser' and $pass = 'prodPass'
.

So, my question is, how do connect to MySQL in the testing server with

Code: Select all

$user = 'prodUser' and $pass = 'prodPass'


instead of

Code: Select all

$user = 'root' and $pass = 'mampPassword'
?

I *know* I can just comment out the code and switch it at production... but that seems like an unnecessary step. Any ideas?

Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 1 guest