tableList() public method

public tableList ( $db = null )
示例#1
0
function convert_tables($db_config, $rules_config, $table_name)
{
    // connect db
    $mysql = new MeekroDB($db_config['host'], $db_config['user'], $db_config['pass'], $db_config['db'], $db_config['port'], $db_config['enc']);
    // convert list
    $table_list = array();
    if ($table_name != '') {
        $table_list = array($table_name);
    } else {
        $table_list = $mysql->tableList();
    }
    foreach ($table_list as $t) {
        if ($rules_config[$t] == NULL) {
            continue;
            // no convert rule
        }
        // load convert config
        $rule_list = $rules_config[$t];
        // load old data
        $rows = $mysql->query("SELECT * FROM %b", $t);
        foreach ($rows as $r) {
            // for each convert config
            foreach ($rule_list as $rule) {
                $tablename = $rule['table'];
                $convertor = $rule['func'];
                // convert data
                $newrow = $convertor($mysql, $r);
                if (empty($newrow)) {
                    continue;
                    // convert error
                }
                $values = '';
                $keys = array_keys($newrow);
                foreach ($keys as $k) {
                    $values .= ' ' . $k . "='" . mysql_escape_string($newrow[$k]) . "',";
                }
                if (strlen($values) > 0) {
                    $values = substr($values, 0, -1);
                }
                // generate insert sql
                $sql = 'INSERT INTO ' . $tablename . ' SET' . $values . ';';
                echo $sql . "\n";
            }
        }
    }
}