--- a/data/class/pages/admin/basis/LC_Page_Admin_Basis_ZipInstall.php
+++ b/data/class/pages/admin/basis/LC_Page_Admin_Basis_ZipInstall.php
@@ -161,10 +161,7 @@
$objQuery =& SC_Query_Ex::getSingletonInstance();
// DB更新
- $objQuery->begin();
- $this->lfDeleteZip();
$this->insertMtbZip();
- $objQuery->commit();
}
/**
@@ -232,34 +229,43 @@
$cntInsert = 0;
$img_cnt = 0;
- $fp = $this->openZipCsv();
- while (!feof($fp)) {
- $arrCSV = fgetcsv($fp, ZIP_CSV_LINE_MAX);
- if (empty($arrCSV)) continue;
- $cntCurrentLine++;
- if ($cntCurrentLine >= $start) {
- $sqlval = array();
- $sqlval['zip_id'] = $cntCurrentLine;
- $sqlval['zipcode'] = $arrCSV[2];
- $sqlval['state'] = $arrCSV[6];
- $sqlval['city'] = $arrCSV[7];
- $sqlval['town'] = $arrCSV[8];
- $objQuery->insert('mtb_zip', $sqlval);
+ /* 標準実装が非常に遅いので Azure/WebMatrix 向けにチューニング */
+ $begin = microtime(true);
+
+ try {
+ $dbh = new PDO('mysql:host=' . DB_SERVER . ';dbname=' . DB_NAME . ';port=' . DB_PORT . ';charset=utf8', DB_USER, DB_PASSWORD);
+ $dbh->beginTransaction();
+ $dbh->exec('DELETE FROM mtb_zip');
+
+ $sql = 'INSERT INTO mtb_zip (zip_id, zipcode, state, city, town) VALUES (?, ?, ?, ?, ?)';
+ $stmt = $dbh->prepare($sql);
+ $line = file(ZIP_CSV_UTF8_REALFILE);
+ for($i = 0; $line[$i] != ''; $i ++){
+ if (!($array = explode(",", $line[$i]))) {
+ continue;
+ }
+ $stmt->bindParam(1, ++$cntCurrentLine, PDO::PARAM_INT);
+ $stmt->bindParam(2, $array[2], PDO::PARAM_STR, strlen($array[2]));
+ $stmt->bindParam(3, $array[6], PDO::PARAM_STR, strlen($array[6]));
+ $stmt->bindParam(4, $array[7], PDO::PARAM_STR, strlen($array[7]));
+ $stmt->bindParam(5, $array[8], PDO::PARAM_STR, strlen($array[8]));
+ $stmt->execute();
$cntInsert++;
- }
- // $disp_line件ごとに進捗表示する
- if ($cntCurrentLine % $disp_line == 0 && $img_cnt < IMAGE_MAX) {
- echo '';
- SC_Utils_Ex::sfFlush();
- $img_cnt++;
+ // $disp_line件ごとに進捗表示する
+ if ($i % $disp_line == 0 && $img_cnt < IMAGE_MAX) {
+ echo '';
+ SC_Utils_Ex::sfFlush();
+ $img_cnt++;
+ }
+ SC_Utils_Ex::extendTimeOut();
}
- SC_Utils_Ex::extendTimeOut();
- }
- fclose($fp);
-
- echo '';
+ $end = microtime(true);
+ echo '';
+ } catch (PDOException $e) {
+ trigger_error($e->getMessage(), E_USER_ERROR);
+ }
?>