note 104283 added to function.mysql-connect
| From: | bimal at sanjaal dot com | Date: | Sun, 05 Jun 2011 19:09:18 +0000 |
| Subject: | note 104283 added to function.mysql-connect | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-180285@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.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.
----
Server IP: 69.147.83.197
Probable Submitter: 110.34.0.242 (proxied: 116.66.193.69)
----
Manual Page -- http://www.php.net/manual/en/function.mysql-connect.php
Edit -- https://master.php.net/note/edit/104283
Del: integrated -- https://master.php.net/note/delete/104283/integrated
Del: useless -- https://master.php.net/note/delete/104283/useless
Del: bad code -- https://master.php.net/note/delete/104283/bad+code
Del: spam -- https://master.php.net/note/delete/104283/spam
Del: non-english -- https://master.php.net/note/delete/104283/non-english
Del: in docs -- https://master.php.net/note/delete/104283/in+docs
Del: other reasons-- https://master.php.net/note/delete/104283
Reject -- https://master.php.net/note/reject/104283
Search -- https://master.php.net/manage/user-notes.php