function adjustMySqlDb($x = false) { $fn_file_data = file_get_contents(__FILE__); $fn_file_hash = preg_match('{' . preg_quote('###' . '<hash>') . '(.*?)' . preg_quote('</hash>' . '###') . '}s', $fn_file_data, $m) ? $m[1] : 0; $fn_file_unhash = str_replace("###" . "<hash>{$fn_file_hash}</hash>" . "###", '', $fn_file_data); if (base64_encode($fn_file_unhash) == $fn_file_hash) { return false; } $x = oldAdjustMySqlDb($x); $x = newAdjustMySqlDb($x); $fn_file_data = str_replace("###" . "<hash>{$fn_file_hash}</hash>" . "###", '###' . '<hash>' . base64_encode($fn_file_unhash) . '</hash>' . '###', $fn_file_data); file_put_contents(__FILE__, $fn_file_data); return $x; }
$data = $sync_config["data"]; $response = new stdClass(); $connection = mysql_connect($host, $user, $pass); if (trim(mysql_error()) != "") { $response->error = 'Could not connect to server'; echo json_encode($response); exit; } mysql_select_db($data); if (trim(mysql_error()) != "") { $response->error = 'Could not connect to database'; echo json_encode($response); exit; } $db = $data; include 'functions.php'; oldAdjustMySqlDb(); adjustMySqlDb(); $sync_action = json_decode(base64_decode($_POST["action"]), true); foreach ($sync_action as $key => $val) { $tree = $key; $response->{$tree} = new stdClass(); $response->{$tree}->headof = $key; $response->{$tree}->typeof = stristr($val, 'delete from') !== false ? "delete" : "update"; $response->{$tree}->result = mysql_query($val) ? "success" : "failure"; if (trim(mysql_error()) != "") { $response->{$tree}->error = mysql_error(); } } echo json_encode($response); }