public static function insert($sql) { $sql = str_replace("\r", "\n", $sql); $sql = explode(";\n", $sql); foreach ($sql as $value) { $value = trim($value); if (empty($value)) { continue; } \Console\System\Db::query($value); } }
public static function seeder() { $param = config::param(); $table_name = $param[0]; $new_file = config::database() . '/seeds/' . $table_name . '.php'; if (empty($table_name)) { return "[0;41;1m table_name isnull\n"; } if (is_file($new_file)) { return "[0;41;1m{$table_name} is has\n"; } $filename = config::database() . '/migrations/' . $table_name . '.php'; if (!is_file($filename)) { return "[0;41;1mnot find this {$table_name} migrate\n"; } $sql = "DESC {$table_name}"; $rs = System\Db::query($sql); $str_sql = ''; while ($row = $rs->fetch()) { $value = $row['Default']; if (empty($row['Default'])) { $value = $row['Field']; } if (!empty($str_sql)) { $str_sql = $str_sql . ','; } $str_sql = $str_sql . "'{$value}'"; } $nest = 'INSERT INTO `' . $table_name . '` VALUES (' . $str_sql . ');'; if (!is_dir(dirname($new_file))) { mkdir(dirname($new_file), 0755, true); } file_put_contents($new_file, $nest); echo "\ncreate {$table_name} successfully\n"; }