treehouse : what would you like to learn today?
Web Design Web Development iOS Development

Help with Database Setup locally and remotely

  • Hi folks, wondered if somebody could help me with database setup. I have followed the database setup locally and it works fine. I have setup a database in my hosting account and it works fine. But I am getting really confused when I move from one to the other. I'm probably not making myself very clear so I will try to explain...

    When my database is set up I can find the file within the Connections folder, within the code section I see this:

    <?php<br /># FileName="Connection_php_mysql.htm"
    # Type="MYSQL"
    # HTTP="true"
    $hostname_dbtest = "localhost";
    $database_dbtest = "dbtest";
    $username_dbtest = "root";
    $password_dbtest = "root";
    $dbtphone = mysql_pconnect($hostname_dbtphone, $username_dbtphone, $password_dbtphone) or trigger_error(mysql_error(),E_USER_ERROR);
    ?>

    This is the part that I am getting confused with and because it is not setup correctly I keep getting this error:

    MySQL Error#:1045
    Access denied for user 'web40-dbtest'@'localhost'(using password: YES)

    To try and keep things simple I named by database locally dbtest and then remotely on my hosting account I use the database setting which is always web#_dbName. I record the username and passwords so I know I have entered them correctly. I do get confused thou with $hostname - locally I enter "localhost" but I'm not sure what to put for remote bit, I usually put my http://www.domain.com name.

    My problems arise after I have setup my database locally meaning:

    I start with a blank sheet and blank database and build my website using Live View for testing, when I am happy with this I then copy the database and import this into the remote database that I have created and move all my files over and voila it works. However, my problems arise when I want to make some changes but I don't want to amend them remotely (just in case), so when I try to change the settings back to local and use LIve View, this is when I get the MySql Error 1045. Hope all this makes sense?

    I would really really appreciate it if somebody could guide me in the right direction with these settings.

    Many thanks
    Vonnie








  • This does not make a whole lot of sense, but I will try to recap it to make sure that I understand.

    1. You are working in two different environments. One locally with a stack on your system, and then one with your hosting provider.
    2. If you set them up either locally or remotely, they work.
    3. If you copy the local version to the remote version, it works.
    4. If you copy the remote version to the local version, it does not work.

    Is that right? When you are connecting to the remote database from your locally run project, there is an issue? Did you allow the database user to have remote access? Or for the database to accept remote connections?
  • Hiya, yes sorry it's difficult to make sense. Yes I think we are okay upto 4. It is when I have everything up and running remotely I can make amendments to my database through phpmyadmin fine and I can make changes to my php pages remotely but I don't like doing this in case I make a mistake and it doesn't look good or I mess up something important and my whole site goes down.

    So I wanted to revert back to working on things locally and then copying across any changes to the php pages on the remote server and just save the updated local database and import that into the remote database so that all the database changes are current and will correspond with the new updated php pages.

    But my problems are arising with the mySql database settings and I cannot get my local environment to work with either the local or remote database once I have changed the settings to work remotely.

    What I am basically trying to do is add more fields to my database and then add the necessary recordsets into existing php pages, so that the admin side of my site works more dynamically??

    Gosh I am so sorry if this sounds like double dutch! Hope you get my drift?

    Cheers
    Vonnie