Created
November 18, 2020 08:25
-
-
Save tinshade/f5b94310e8742a665f8f23d13e571c63 to your computer and use it in GitHub Desktop.
Simple PHP database configuration script that automatically switches between local and production databases based on the server it is being run on.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$whitelist = array('127.0.0.1','::1'); | |
if(!in_array($_SERVER['REMOTE_ADDR'], $whitelist)){ | |
//SERVER | |
$server = 'localhost'; | |
$username = 'server_username'; | |
$password = 'server_password'; | |
$dbname = 'username_dbname'; | |
$conn = mysqli_connect($server, $username, $password, $dbname); | |
if (!$conn){ | |
die("Connection Failed! ".mysqli_connect_error()); | |
} | |
}else{ | |
//LOCAL | |
$server = 'localhost'; | |
$username = 'root'; | |
$password = ''; | |
$dbname = 'dbname'; | |
$conn = mysqli_connect($server, $username, $password, $dbname); | |
if (!$conn){ | |
die("Connection Failed! ".mysqli_connect_error()); | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment