#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Location
    Edinburgh
    Posts
    19
    Rep Power
    0

    Question Change Localhost to IP or URL


    Hi guys.... I'm new so please treat with care

    Can anyone please help me with the following.

    I have a file that saved data to a database. In the connection details the host is set to "localhost". Is it possible to change it from localhost to a server ip or url as the database will be sitting on a different server.

    I've tried changing "localhost" to an "ip" myself but i cannot connect to the server.

    Thanks

    Hudbarnett
  2. #2
  3. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,957
    Rep Power
    1046
    Hi,

    this is much too vague. What's your concrete code? (without passwords etc. of course) What exactly happens? Which error messages do you get?

    Have you tried connecting from a different (e. g. your local) server?
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Location
    Edinburgh
    Posts
    19
    Rep Power
    0
    Originally Posted by Jacques1
    Hi,

    this is much too vague. What's your concrete code? (without passwords etc. of course) What exactly happens? Which error messages do you get?

    Have you tried connecting from a different (e. g. your local) server?
    Hi there

    Sorry i'm new to this. Here are my connection details, when i run the page on my server its working fine but when i try to point the below connection to a different page it errors. The error is is form the page with the connection details. I have tried changing the localhost like this $host=#.#.#.#:3306; but still no joy

    $host="localhost"; // Host name
    $username="######"; // Mysql username
    $password="######"; // Mysql password
    $db_name="######"; // Database name
    $tbl_name="######"; // Table name


    Thanks for any help you can provide and sorry if there isn't enough info here

    Hudbarnett
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2009
    Posts
    676
    Rep Power
    7
    So, the site will run on one server, while the database sits on another? You can simple set the IP in your site's config, BUT, the database server will also need to be set to accept connections from external clients/IP addresses.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Location
    Edinburgh
    Posts
    19
    Rep Power
    0
    Originally Posted by Triple_Nothing
    So, the site will run on one server, while the database sits on another? You can simple set the IP in your site's config, BUT, the database server will also need to be set to accept connections from external clients/IP addresses.
    Hi there, yes the site will run on one server and connect out to a database server. When you say site's config do you mean the php,ini file?

    Sorry i'm new to php

    Thanks

    Hudbarnett
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2009
    Posts
    676
    Rep Power
    7
    Well, site's config I meant the items you referenced in ur past post. Server's config will need to allow connections from external items. What kind of error do you get?
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Location
    Edinburgh
    Posts
    19
    Rep Power
    0
    Originally Posted by Triple_Nothing
    Well, site's config I meant the items you referenced in ur past post. Server's config will need to allow connections from external items. What kind of error do you get?
    The error that i receive is a basic error from the php code. I setup "echo "ERROR";" if the code doesn't work. It doesn't say anything else over and above that.

    Thanks

    Hudbarnett
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2009
    Posts
    676
    Rep Power
    7
    If the only thing changing is localhost to an IP, I'm assuming you're receiving a connection error. Could we see the rror you receive?
  16. #9
  17. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Location
    Edinburgh
    Posts
    19
    Rep Power
    0
    Originally Posted by Triple_Nothing
    If the only thing changing is localhost to an IP, I'm assuming you're receiving a connection error. Could we see the rror you receive?
    Hi there

    here is the error that i receive.

    Warning: mysql_connect() [function.mysql-connect]: Unknown MySQL server host ' 212.48.67.38' (1) in /var/www/survey/insert_ac.php on line 10
    cannot connect
  18. #10
  19. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2009
    Posts
    676
    Rep Power
    7
    It seems either that is not the server's IP. If the server DOES sit behind that IP, a firewall may be blocking external access.
  20. #11
  21. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Location
    Edinburgh
    Posts
    19
    Rep Power
    0
    Originally Posted by hudbarnett
    Hi there

    here is the error that i receive.

    Warning: mysql_connect() [function.mysql-connect]: Unknown MySQL server host ' 212.48.67.38' (1) in /var/www/survey/insert_ac.php on line 10
    cannot connect
    Hi there, i have managed to fit it and get this working. I left a space before the IP address. Also the ERROR message that i got was due to the form trying to echo a message and redirect to another page.

    I would like to thank everyone who has helped me. Thanks guys
  22. #12
  23. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,957
    Rep Power
    1046
    Originally Posted by hudbarnett
    I left a space before the IP address.
    And that's why we always ask people to post the exact error message. In your case, the error message actually shows the space before the IP.
  24. #13
  25. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Location
    Edinburgh
    Posts
    19
    Rep Power
    0
    Originally Posted by Jacques1
    And that's why we always ask people to post the exact error message. In your case, the error message actually shows the space before the IP.
    Thanks Jacques1

IMN logo majestic logo threadwatch logo seochat tools logo