note 104284 modified in function.mysql-connect by danbrown
| From: | danbrown@php.net | Date: | Sun, 05 Jun 2011 19:41:53 +0000 |
| Subject: | note 104284 modified in function.mysql-connect by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-180288@lists.php.net to get a copy of this message | ||
Portable connections: If you migrate your source code from one to different servers and you would
like to avoid re-configuration on a new serve, user the $_SERVER['SERVER_NAME'] flag as:
<?php
switch($_SERVER['SERVER_NAME'])
{
case 'server1.example.com':
mysqlconnect('host1', 'user1', 'password1');
mysql_select_db('db1');
break;
case 'server2.example.com':
mysqlconnect('host2', 'user2', 'password2');
mysql_select_db('db2');
break;
}
?>
This makes a conditional connection to mysql database. It automatically chooses the correct server
according to the server name from where your script runs.
Hopefully, you like this portable configuration.
--was--
Portable connections: If you migrate your source code from one to different servers and you would
like to avoid re-configuration on a new serve, user the $_SERVER['SERVER_NAME'] flag as:
<?php
switch($_SERVER['SERVER_NAME'])
{
case 'server1.domain.com':
mysqlconnect('host1', 'user1', 'password1');
mysql_select_db('db1');
break;
case 'server2.domain.com':
mysqlconnect('host2', 'user2', 'password2');
mysql_select_db('db2');
break;
}
?>
This makes a conditional connection to mysql database. It automatically chooses the correct server
according to the server name from where your script runs.
Hopefully, you like this portable configuration.
http://php.net/manual/en/function.mysql-connect.php