Jump to content

[SOLVED] Best way the same DB locally and online.


Recommended Posts

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!

 

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

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.