/**
 * Changes master for replication slave
 *
 * @param string $user     replication user on master
 * @param string $password password for the user
 * @param string $host     master's hostname or IP
 * @param int    $port     port, where mysql is running
 * @param array  $pos      position of mysql replication,
 *                         array should contain fields File and Position
 * @param bool   $stop     shall we stop slave?
 * @param bool   $start    shall we start slave?
 * @param mixed  $link     mysql link
 *
 * @return string output of CHANGE MASTER mysql command
 */
function PMA_Replication_Slave_changeMaster($user, $password, $host, $port, $pos, $stop = true, $start = true, $link = null)
{
    if ($stop) {
        PMA_Replication_Slave_control("STOP", null, $link);
    }
    $out = $GLOBALS['dbi']->tryQuery('CHANGE MASTER TO ' . 'MASTER_HOST=\'' . $host . '\',' . 'MASTER_PORT=' . $port * 1 . ',' . 'MASTER_USER=\'' . $user . '\',' . 'MASTER_PASSWORD=\'' . $password . '\',' . 'MASTER_LOG_FILE=\'' . $pos["File"] . '\',' . 'MASTER_LOG_POS=' . $pos["Position"] . ';', $link);
    if ($start) {
        PMA_Replication_Slave_control("START", null, $link);
    }
    return $out;
}
/**
 * handle control requests for Slave Skip Error
 *
 * @return boolean
 */
function PMA_handleRequestForSlaveSkipError()
{
    $count = 1;
    if (isset($_REQUEST['sr_skip_errors_count'])) {
        $count = $_REQUEST['sr_skip_errors_count'] * 1;
    }
    $qStop = PMA_Replication_Slave_control("STOP");
    $qSkip = $GLOBALS['dbi']->tryQuery("SET GLOBAL SQL_SLAVE_SKIP_COUNTER = " . $count . ";");
    $qStart = PMA_Replication_Slave_control("START");
    $result = $qStop !== false && $qStop !== -1 && $qSkip !== false && $qSkip !== -1 && $qStart !== false && $qStart !== -1;
    return $result;
}
/**
 * handle control requests for Slave Skip Error
 *
 * @return NULL
 */
function PMA_handleRequestForSlaveSkipError()
{
    $count = 1;
    if (isset($_REQUEST['sr_skip_errors_count'])) {
        $count = $_REQUEST['sr_skip_errors_count'] * 1;
    }
    PMA_Replication_Slave_control("STOP");
    $GLOBALS['dbi']->tryQuery("SET GLOBAL SQL_SLAVE_SKIP_COUNTER = " . $count . ";");
    PMA_Replication_Slave_control("START");
}