Announcement

Collapse
No announcement yet.

Need to connect to a remote database.

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Need to connect to a remote database.

    NOT ABOUT VB BUT PHP HELP

    Hello,

    Here is the code I use to connect to a database n the same server:

    //MYSQL DATABASE SETUP
    $user = "username";
    $password = "xxxxxxx";
    $db = "db_name";
    $server = "localhost";

    Can anyone help me with the PHP code to
    connect to a DB on a different server entirly?

    Thanks in advance!
    JackG

  • #2
    PHP Code:

    $hostname 
    =  "255.255.255.255";  // host 
    $username =  "db_user";       // user 
    $password =  "db_pass";    // password 
    $dbName =  "db_name";      // dbname

    MYSQL_CONNECT($hostname$username$password) OR DIE( "Unable to connect to database");

    //Your stuff here

    MYSQL_CLOSE(); 

    Just change 255.255.255.255 to the IP or hostname of the mysql server....

    Comment


    • #3
      Thanks- The Prohacker . I will give it a shot!
      JackG

      Comment


      • #4
        hmmm. I am using this DB connction in a
        Common.php file. Added all the right data but get
        this error:


        Warning: MySQL Connection Failed: Access denied for user: '[email protected]' (Using password: YES) in /home/sites/site4/web/propview.php on line 7
        Couldn't connect to mySQL server


        So it looks like its not letting site A connect to the database on
        site B

        Do i need to give a permission to site A

        Any ideas?
        Last edited by JackG; Mon 26 Nov '01, 2:05pm.
        JackG

        Comment


        • #5
          Your mysql may not be set up to allow external connections to the database.

          Contact your host.
          Email: [email protected]
          Site: Under Construction

          Comment


          • #6
            thanks I will ask them and see what happens.
            JackG

            Comment


            • #7
              Originally posted by JackG
              thanks I will ask them and see what happens.
              I dont think they will because it opens the server (and your databases) to attack.
              Email: [email protected]
              Site: Under Construction

              Comment


              • #8
                I wrote to them lets see what happens.
                Its just my otehr IP that needs acces. i will post back.
                JackG

                Comment


                • #9
                  You can grant access to a specific user from a specific IP or hostname. It's just up to your host to make that decission. If they don't you might try badgering them.

                  And if they play dumb, post back here and we'll give you the SQL queries to email them.

                  Muhahaha!

                  Comment


                  • #10
                    Well if the other IP is bound to the same server, you can still just use localhost.. Because MySql doesn't bind to a specific IP....

                    Comment


                    • #11
                      hehe thanks!

                      I am still waiting for there responce.

                      Here is what i am trying to do..
                      I have a real estate listing service online.
                      1 major site & 1 smaller one.

                      I want:

                      Site A to view both Site A's and Site B's data

                      But Site A can only see Site A's data.

                      So if you place a listing on site B it will appear only on site B

                      But if you place a listing on site A your get a listing on both
                      site A & B.


                      Has anyone here done this?
                      JackG

                      Comment

                      widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
                      Working...
                      X