note 104876 added to function.mysql-connect
| From: | hungry dot mind at hotmail dot com | Date: | Wed, 13 Jul 2011 06:02:43 +0000 |
| Subject: | note 104876 added to function.mysql-connect | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-181452@lists.php.net to get a copy of this message | ||
Code:
One MySQL Database Connection Is Handling 3 Process.
1st for Local PC, 2nd for Local Network PC using It's IP Series, 3rd for Hosting Server.
You Can Make It One Time Database Connection For Multipurpose.
<?php
// Setting IP's
define("USER_IP", $_SERVER['REMOTE_ADDR']);
define("LOCAL_IP", '127.0.0.1'); // Local System IP
$IP_Series = '192.168.1.'; // Local Network IP Series
for ($i=0; $i<256; $i++)
{
$set_IP = $IP_Series . $i;
if (USER_IP == $set_IP)
{
define("LOCAL_NETWORK_IP", $set_IP); // Finding Local Network System IP
}
}
define("HOSTING_SERVER_IP", ''); // Hosting Server IP, Not Necessary, It Will
Work On Default
switch (USER_IP)
{
case LOCAL_IP:
// Setting Local Computer IP
define("LOCALHOST", "localhost");
define("USERNAME", "root");
define("PASSWORD", "");
define("DATABASE", "database");
break;
case LOCAL_NETWORK_IP:
// Setting Local Network System IP
define("LOCALHOST", "localhost");
define("USERNAME", "root");
define("PASSWORD", "");
define("DATABASE", "database");
break;
default:
// Setting Hosting Server IP
define("LOCALHOST", "localhost");
define("USERNAME", "root");
define("PASSWORD", "");
define("DATABASE", "database");
}
// Database Connection
(!$db = mysql_connect(LOCALHOST, USERNAME, PASSWORD)) ? die('DB Connection Error: ' .
mysql_error()) : (!mysql_select_db(DATABASE, $db)) ? die('DB Selection Error: ' .
mysql_error()) : '';
?>
----
Server IP: 69.147.83.197
Probable Submitter: 116.71.19.75
----
Manual Page -- http://www.php.net/manual/en/function.mysql-connect.php
Edit -- https://master.php.net/note/edit/104876
Del: integrated -- https://master.php.net/note/delete/104876/integrated
Del: useless -- https://master.php.net/note/delete/104876/useless
Del: bad code -- https://master.php.net/note/delete/104876/bad+code
Del: spam -- https://master.php.net/note/delete/104876/spam
Del: non-english -- https://master.php.net/note/delete/104876/non-english
Del: in docs -- https://master.php.net/note/delete/104876/in+docs
Del: other reasons-- https://master.php.net/note/delete/104876
Reject -- https://master.php.net/note/reject/104876
Search -- https://master.php.net/manage/user-notes.php