sending data to database at remote host

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kagiso boikanyo
    New Member
    • Mar 2011
    • 6

    sending data to database at remote host

    I would love to know whether this code is the correct manner to send mysql data to a remote host.

    Code:
        $host = 'www.domain.tld';
        $user = 'remote_user';
        $pass = 'remote_password';
    
        $time_end = microtime(true);
    
        //grant per;misions to connect to remote host
        if (!function_exists("ssh2_connect")) die("function ssh2_connect doesn't exist");
    
        // log in at server1.example.com on port 22
        if (!($con = ssh2_connect("www.domain.tld", 22))) {
        echo "fail: unable to establish connection\n";
        } else {
        
        // try to authenticate with username root, password secretpassword
        if (!ssh2_auth_password($con, "remote_user", "remote_password")) {
            echo "fail: unable to authenticate\n";
        } else {
            
            echo "okay: logged in...\n";
         
                // grant priveliges to access remote database
    			$priveleges="GRANT ALL ON dest_table.create_info.* TO '    remote_user'@'www.domain.tld'";            
                //dump database to a file
    			$dump = "mysqldump -u remote_user -p Profusion.source_cadre >  Profusion.source_cadre.sql"; 
                //now compress file for faster upload
                $compress="tar zcf Profusion.source_cdr.tar.gz dest_table.sql";
    			//now start decompressing the file
    			$decom="tar zxf dumpfilename.tar.gz";
    			//now import the file to the database;
    			$import="mysql -u remote_user -p dest_table.create_info < Profusion.source_cdr.sql";
    			//get the number of rows inserted
                $progress=mysql_affected_rows();
                exec ($priveleges,$dump,$compress,$decom,$import);
                sleep(1);
                
               
         }

    I am unable to test this code at the present moment

    Your help will be highly appreciated.
    Last edited by Rabbit; Jan 11 '14, 08:51 PM. Reason: Please use [CODE] and [/CODE] tags when posting code or formatted data.
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    line #33 will throw an error. you use the CLI yet try to get the result from a PHP function.

    Comment

    • kagiso boikanyo
      New Member
      • Mar 2011
      • 6

      #3
      Hi Dormilich, what I am actually trying to do is to find the number of rows that will be affected by the query so that I can try to calculate the time taken for each row to be inserted and then display a progress bar based on that calculation.

      Is there a better way to go about this??

      Thanks alot for your help.

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        what I am actually trying to do is to find the number of rows that will be affected by the query so that I can try to calculate the time taken for each row to be inserted
        to find out how fast MySQL operates, consult the Query Log.

        doing that on-the-fly is a bit pointless, since you need to wait for the results while mysql is already working.

        Comment

        • Dormilich
          Recognized Expert Expert
          • Aug 2008
          • 8694

          #5
          what I am actually trying to do is to find the number of rows that will be affected by the query so that I can try to calculate the time taken for each row to be inserted
          to find out how fast MySQL operates, consult the Query Log.

          doing that on-the-fly is a bit pointless, since you need to wait for the results while mysql is already working.

          Comment

          • kagiso boikanyo
            New Member
            • Mar 2011
            • 6

            #6
            Okay I understand Dormilich, thanks alot for your help.

            Comment

            Working...