如何将本地数据库数据与实时mysql服务器同步?

In my application i want to transfer data from one server to many clients and vice versa. I had done it by making controller called “syncs” in server side which contains method called “export_data” which converts data into transferable format now i transfer that data to method called “post_data” that contains a link of clients controller “sync” which has method called “import_data” now this import_data method is start inserting that data to table if “is_sync” column in servers table is set to “0” if that has value “1” then it shows already sync data as alert message.

but nothing is happened when i send data from server to client.

all_set.php

   $.post('<?=base_url("syncs/export_data")?>',{ tablename : 
          'sma_class_set', ids : arr , async : true , cache : false}, 
           function(ret){
             alert(arr);
   });

syncs.php

function export_data(){

    $data = NULL;

    if ( $_POST ) {
        $table = $this->db->escape_str($_POST['tablename']);
        $sales_id = $_POST['ids'];
        $in_ids = implode(",", $sales_id);

        if ( isset( $sales_id ) && !empty( $sales_id ) ) {

            $sql = $this->db->query("SELECT * FROM `$table` WHERE `is_synced` = '0' AND `".$this->tables[$table]['exclude']."` IN($in_ids) ");

        } else {

            $sql = $this->db->query("SELECT * FROM `$table` WHERE `is_synced` = '0' ");
        }

        if ( !empty($sql->result_array()) ) {

            $final = $str_array = array();

            foreach ( $sql->result_array() as $sk => $sv){

                $col = array();

                foreach ($sv as $svk => $svl) {

                    if ( $svk != $this->tables[$table]['exclude'] ) {

                        array_push($col, "'$svl'");
                    }
                }

                array_push($final, explode("|", "(".implode(",", $col).")|"));
            }

            foreach ($final as $fk => $fv) {

                array_push($str_array, $fv[0]);
            }

            $str = implode(",", $str_array);

            $output = "INSERT INTO `$table`(".$this->tables[$table]['include'].") VALUES $str";


            if ( filter_var($this->post_data($output), FILTER_VALIDATE_INT) === false ) {

                $data = $this->post_data($output);

            } else {

                $this->db->query("UPDATE `$table` SET `is_synced` = '1' WHERE `".$this->tables[$table]['exclude']."` IN($in_ids) ");
                $data = "Data Synced Successfully";
            }

        } else {

            $data = "Already synced data";
        }
    } else {

        $data = "Error no values posted";
    }

    echo $data;
}
function post_data($qry){

    $qry = htmlspecialchars(urlencode($qry));
    $data = "qry=" . $qry;
    $ch = curl_init();
    curl_setopt( $ch, CURLOPT_URL,"http://localhost/BDS/pos_app/sync/import_data" );//Localhost url here
    curl_setopt( $ch, CURLOPT_AUTOREFERER, 1);
    curl_setopt ( $ch, CURLOPT_HTTPHEADER, array ( 'Content-length: ' . strlen($qry)+1 ) );
    curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt( $ch, CURLOPT_POST,1);
    curl_setopt( $ch, CURLOPT_POSTFIELDS,$data);
    curl_setopt( $ch, CURLOPT_CRLF, 1);
    $result = curl_exec($ch);
    curl_close($ch);
    return $result;
}

clientside "sync.php" which now import data using "import_data" function

sync.php

function import_data(){

    $return = "";

    if ( isset( $_POST['qry'] ) && !empty( $_POST['qry'] ) ) {

        $qry = htmlspecialchars_decode( urldecode( $_POST['qry']));
        $this->db->trans_start();
        $this->db->query($qry);
        $insert_id = $this->db->insert_id();
        $this->db->trans_complete();

        if ($this->db->trans_status() === FALSE) {

            # Something went wrong.
            $this->db->trans_rollback();
            $return = "Error transaction could not be completed";
        } 
        else {

            # Everything is Perfect. 
            # Committing data to the database.
            $this->db->trans_commit();
            $return = $insert_id;
        }

    }else{

        $return = "Data do not received in proper way";
    }

    echo $return;
}