コード例 #1
0
 public function cleanup_slave($slaveId)
 {
     // ensure old slave is disconnected
     sql_disconnect_slave();
     // connect the slave
     if ($slaveId == -1) {
         sql_connect_master_as_slave();
     } else {
         sql_connect_slave($slaveId);
     }
     $this->cleanup_mapresult2($slaveId);
     // disconnect slave
     sql_disconnect_slave();
 }
コード例 #2
0
ファイル: db.inc.php プロジェクト: kirstenko/oc-server3
function sql_connect_slave($id)
{
    global $opt, $db;
    if ($id == -1) {
        sql_connect_master_as_slave();
        return;
    }
    // the right slave is connected
    if ($db['dblink_slave'] !== false) {
        // TODO: disconnect if other slave is connected
        if ($db['slave_id'] != $id) {
            sql_error();
        }
        return;
    }
    $db['slave_id'] = $id;
    $slave = $opt['db']['slaves'][$id];
    // for display in SQL debugger
    $db['slave_server'] = $slave['server'];
    if ($opt['db']['pconnect'] == true) {
        $db['dblink_slave'] = @mysql_pconnect($slave['server'], $slave['username'], $slave['password']);
    } else {
        $db['dblink_slave'] = @mysql_connect($slave['server'], $slave['username'], $slave['password']);
    }
    if ($db['dblink_slave'] !== false) {
        if (mysql_select_db($opt['db']['placeholder']['db'], $db['dblink_slave']) == false) {
            sql_error();
        }
        mysql_query("SET NAMES '" . mysql_real_escape_string($opt['charset']['mysql'], $db['dblink_slave']) . "'", $db['dblink_slave']);
        // initialize temp tables on slave server
        $rs = sqlf_slave("SELECT `threadid`, `name` FROM `sys_temptables` WHERE `threadid`='&1'", mysql_thread_id($db['dblink_slave']));
        while ($r = sql_fetch_assoc($rs)) {
            sqlf_slave("DROP TEMPORARY TABLE IF EXISTS &tmpdb.`&1`", $r['name']);
        }
        sql_free_result($rs);
        sqlf_slave("DELETE FROM &db.`sys_temptables` WHERE `threadid`='&1'", mysql_thread_id($db['dblink_slave']));
    } else {
        sql_error();
    }
}