Loading ...
Sorry, an error occurred while loading the content.
 

php code to remote MYSQL database problem

Expand Messages
  • Tushar Saha
    Hello All, I ve tried the following code but failed. why it doesn t work and what s the solution.
    Message 1 of 7 , Oct 22, 2008
      Hello All,
      I've tried the following code but failed. why it doesn't work and what's the solution.
      <?
      $hostname = "mysqlhost.netfirms.com:3306"; //My remote host
      $username= "username";
      $password= "password";
      $dbid="dbid"; //Remotedb

      $link=mysql_connect($hostname, $username, $password);
      mysql_select_db($dbid) or die ("Unable to connect to MySQL");
      print "Connected to MySQL";
      mysql_close($link);
      ?>


      Thanks
      Tushar

    • Jim Byrnes
      ... It looks like you did not include the name of the db in your connect statement. Regards, Jim
      Message 2 of 7 , Oct 23, 2008
        Tushar Saha wrote:
        > Hello All,
        > I've tried the following code but failed. why it doesn't work and what's the solution.
        > <?
        > $hostname = "mysqlhost.netfirms.com:3306"; //My remote host
        > $username= "username";
        > $password= "password";
        > $dbid="dbid"; //Remotedb
        >
        > $link=mysql_connect($hostname, $username, $password);
        > mysql_select_db($dbid) or die ("Unable to connect to MySQL");
        > print "Connected to MySQL";
        > mysql_close($link);
        > ?>
        >
        > Thanks
        > Tushar
        >
        >
        >
        >
        It looks like you did not include the name of the db in your connect
        statement.

        Regards, Jim
      • Tushar Saha
        Hello All, Say I ve two domain name domain1.com and domain2.com. I need to access the mysql of domain2.com from domain1.com. Is it possible. If possible how.
        Message 3 of 7 , Oct 24, 2008
          Hello All,
          Say I've two domain name domain1.com and domain2.com.  I need to access the mysql of domain2.com from domain1.com. Is it possible. If possible how. Please say.

          I've tried the following php code to connect remote MYSQL database. Why it doesn't work and what's the solution.
          <?
          $hostname = "mysqlhost.netfirms .com:3306" ; //My remote host
          $username= "username";
          $password= "password";
          $dbid="dbid" ; //Remotedb

          $link=mysql_ connect($ hostname, $username, $password);
          mysql_select_ db($dbid) or die ("Unable to connect to MySQL");
          print "Connected to MySQL";
          mysql_close( $link);
          ?>


          Thanks
          Tushar


        • Arafat Rahman
          Make sure your mysql server of domain2.com supports remote connection. Arafat Rahman http://arafatbd.net
          Message 4 of 7 , Oct 25, 2008
            Make sure your mysql server of domain2.com supports remote connection.

            Arafat Rahman
            http://arafatbd.net

          • Tushar Saha
            Thanks Jim ya, I ve given the name of remote db. Thanks Tushar ________________________________ From: Jim Byrnes To:
            Message 5 of 7 , Oct 25, 2008
              Thanks Jim
              ya, I've given the name of remote db.


              Thanks
               Tushar


              From: Jim Byrnes <jf_byrnes@...>
              To: phpexperts@yahoogroups.com
              Sent: Thursday, October 23, 2008 7:45:47 PM
              Subject: Re: [phpXperts] php code to remote MYSQL database problem

              Tushar Saha wrote:

              > Hello All,
              > I've tried the following code but failed. why it doesn't work and what's the solution.
              > <?
              > $hostname = "mysqlhost.netfirms .com:3306" ; //My remote host
              > $username= "username";
              > $password= "password";
              > $dbid="dbid" ; //Remotedb
              >
              > $link=mysql_ connect($ hostname, $username, $password);
              > mysql_select_ db($dbid) or die ("Unable to connect to MySQL");
              > print "Connected to MySQL";
              > mysql_close( $link);
              > ?>
              >
              > Thanks
              > Tushar
              >
              >
              >
              >
              It looks like you did not include the name of the db in your connect
              statement.

              Regards, Jim


            • Tushar Saha
              Thanks Arafat Bhaia, I m also thinking that. ________________________________ From: Arafat Rahman To: phpexperts@yahoogroups.com Sent:
              Message 6 of 7 , Oct 25, 2008
                Thanks Arafat Bhaia,
                I'm also thinking that.



                From: Arafat Rahman <opurahman@...>
                To: phpexperts@yahoogroups.com
                Sent: Saturday, October 25, 2008 1:12:26 PM
                Subject: Re: [phpXperts] php code to remote MYSQL database problem

                Make sure your mysql server of domain2.com supports remote connection.

                Arafat Rahman
                http://arafatbd. net


              • shiplu
                If the php script is in hostname1 and the mysql server is in hostname2 and you are accessing db database1 with user user1 and password password1, grant the
                Message 7 of 7 , Oct 25, 2008
                  If the php script is in hostname1 and the mysql server is in hostname2 and you are accessing db database1 with user user1 and password password1, grant the privileges to this user on mysql (in hostname2) by following query.

                  grant all privileges on `database1`.* to 'user1'@'hostname1' identified by 'password1';


                  After that you'll be able to access by the following code.

                  $hostname = "hostname2:3306" ; // 
                  $username= "user1";
                  $password= "password1";
                  $dbid="database1" ; //Remotedb

                  $link=mysql_ connect($ hostname, $username, $password) or 
                  die ("Unable to connect to MySQL");
                  mysql_select_ db($dbid, $link);

                  // Do db operation here.

                  mysql_close($link);

                  --
                  A K M Mokaddim
                  http://talk.cmyweb.net
                  http://twitter.com/shiplu
                  Stop Top Posting !!
                Your message has been successfully submitted and would be delivered to recipients shortly.