db = $this->load->database("onedev", true); } function index() { echo "Replication API"; } function slave() { $sql = "show slave status"; $qry = $this->db->query($sql); if (! $qry) { echo json_encode( array("status" => "ERR" , "message" => print_r($this->db->error(),true) ) ); exit; } $rows = $qry->result_array(); $slave = array(); $slave["status"] = "Not Running"; if(count($rows) == 0 ) { echo json_encode($slave); exit; } $r = $rows[0]; $slave["status"] = "Running"; $slave["MasterLogFile"] = $r["Master_Log_File"]; $slave["ReadPosition"] = $r["Read_Master_Log_Pos"]; $slave["Behind"] = $r["Seconds_Behind_Master"]; $slave["Table"] = explode(",", $r["Replicate_Do_Table"]); echo json_encode($slave); } function post($url,$data) { $ch = curl_init($url); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); //curl_setopt($ch, CURLOPT_VERBOSE, true); curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Content-Type: application/json', 'Content-Length: ' . strlen($data)) ); $result = curl_exec($ch); return $result; } }