note 32266 added to function.mysql-connect
| From: | bgw at globe dot net dot nz | Date: | Wed, 21 May 2003 23:42:30 +0000 |
| Subject: | note 32266 added to function.mysql-connect | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-48799@lists.php.net to get a copy of this message | ||
When developing php/mysql on a local machine, then uploading to a remote site, here is a little tip
to speed development and testing when using mysql_connect. This will save you having to change
server info for the connect function.
Note: it assumes a secure development machine as mysql login is default here.
When final testing has passed then the surplus can be deleted and just the remote login details
used.
--------------------------------------
//This script checks if we are on the local development
//machine or scipt is sittiing on the remote server
// Check to see if we are on the local(development machine)
if (getenv ("REMOTE_ADDR") == "127.0.0.1"){
$server_addr = "localhost";
$database = "test";
$user = "root";
$pass = "";
}else{
$server_addr = "db.remoteaddress.com";
$database = "database_name";
$user = "db_user_name";
$pass = "db_password";
}
// Connecting, selecting database
$link = @mysql_connect($server_addr, $user, $pass )
or die("Could not connect to database.");
@mysql_select_db($database)
or die("Could not select database.");
// Regards, Brett
----
Manual Page -- http://www.php.net/manual/en/function.mysql-connect.php
Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+32266
Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+32266&report=yes
Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+32266&report=yes