Maracles Posted October 26, 2009 Share Posted October 26, 2009 I'm new to PHP so haven't quite worked out the work flow properly yet, as such I have a question regarding MySQL databases. For the last couple of weeks I have been making a site offlline and testing on local host, now however I want to upload it to my live test website (password protected) and have done so including uploading the MySQL file. This however caused a problem because the 'mysql_select_db query()' was configured for localhost and not my live server therefore the live page could not initially connect to the database. Therefore to get it working I need to change the code however in doing so it becomes quite frustrating because: a. It would mean I need one set of files with database connection configured for the live server and one set of files for testing which are configured for the local host. b. In turn if I was testing locally and getting certain pages ready, every time I wanted to upload the changes I would have to make copies that included the right database connect code and upload this to the website. Is there a easier workflow for creating and testing files locally but then still having an easy way of uploading them and have all the database connections work smoothly? Basically I want to work locally on my laptop even when disconnected from the laptop and then when a page is finished simply upload it straight to my site and have it working. I know this is badly described but i'm sturggling to explain it :-S! Quote Link to comment https://forums.phpfreaks.com/topic/179125-solved-best-way-the-same-db-locally-and-online/ Share on other sites More sharing options...
ldb358 Posted October 27, 2009 Share Posted October 27, 2009 what i do is i write a db connection file that has all my db info with the same name both local and online then you just include the connection file and when you upload your site(not the db connection file) it will include the appropriate db connection settings without having to change your scripts Quote Link to comment https://forums.phpfreaks.com/topic/179125-solved-best-way-the-same-db-locally-and-online/#findComment-945081 Share on other sites More sharing options...
gevensen Posted October 27, 2009 Share Posted October 27, 2009 i use a flag $deployed=1 for online 0 for local if($deployed==1) { $dbmane= $dbpass= ect } if($deployed==0) { $dbmane= $dbpass= ect } you have to specify the variable as 0 on the local machine and 1 on the web server or use any name you want Quote Link to comment https://forums.phpfreaks.com/topic/179125-solved-best-way-the-same-db-locally-and-online/#findComment-945222 Share on other sites More sharing options...
Maracles Posted October 27, 2009 Author Share Posted October 27, 2009 Sorry, I have only just seen these posts however both seem like good methods. I will try implementing one of them this evening, thanks. Quote Link to comment https://forums.phpfreaks.com/topic/179125-solved-best-way-the-same-db-locally-and-online/#findComment-945732 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.