I have created a few .php webpages using dreamweaver that I am able to run on my localhost. I have a testing server that I use to test my pages before uploading them on my website.
My hostname is: localhost
Database name: WeeklyPlans
Username: user1
Password: password1
All this information is saved in a file saved in a connection folder.
Now when I upload my webpages on the remote server, the settings are different.
Server name (hostname): SQL123
Database name: WeeklyPlans
Username: user1
Password: password1
I have to change the name of the server in the file everytime I upload files. What am I missing here? This is driving me nuts. Can someone please tell me how can I view my webpages on the remote and localhost without changing the hostname?
Thank you.
hostname for testing and remote servers
Moderator: General Moderators
- PHP_mySQL__Newbie
- Forum Commoner
- Posts: 29
- Joined: Fri Aug 12, 2011 5:40 pm
Re: hostname for testing and remote servers
If you're defining your database credentials in some type of config file, you can just have one copy on the test server and one copy on the live server. Configuration files tend to not change terribly often. You could even take that a step farther and have a configuration file that only contains database credentials, precluding it from ever needing to be changed.
Re: hostname for testing and remote servers
And to make sure you didn't accidentally overwrite the different settings on the two hosts, you can "cloak" the config file in DreamWeaver.Celauran wrote:You could even take that a step farther and have a configuration file that only contains database credentials, precluding it from ever needing to be changed.
Am alternative approach might be to assign the items that change between servers to php variables and set their values according to the value of the
Code: Select all
if (isset($_SERVER["SERVER_NAME"]) && $_SERVER["SERVER_NAME"] != "localhost")
{
$hostname = "localhost";
}
else
{
$hostname = "SQL123";
}Code: Select all
$db = new mysqli($hostname, "user1", "password1", "WeeklyPlans");