$pdo = YDLib::getPDO('db_user_w');
$pdo->beginTransaction();
try {
for ($i = 0; $i < 256; $i++) {
$pre = sprintf('%02x', $i % 256);
$sql = <<<sql
ALTER TABLE User_$pre
ADD `Type` tinyint(3) unsigned DEFAULT '1' COMMENT '默認1 系統 2 用戶' AFTER Status,
CHANGE `Money` `Money` decimal(10,2) unsigned NOT NULL COMMENT '財富數額',
sql;
$pdo->exec($sql);
}
$pdo->commit();
echo 'success';
} catch (Exception $e) {
$pdo->rollback();
echo 'fail';
}
分表統計視圖
$pdo = YDLib::getPDO('db_user_w');
$pdo->beginTransaction();
try {
$sql = 'create or replace `UUser` as select * from User_00';
for ($i = 1; $i < 256; $i++) {
$pre = YDLib::table($i);
$sql .= " union all select * from User_{$pre} ";
}
$pdo->exec($sql);
$pdo->commit();
echo 'success';
} catch (Exception $e) {
$pdo->rollback();
echo 'fail';
}