| 1 | #!/usr/local/bin/php -q |
|---|
| 2 | <?php |
|---|
| 3 | /* |
|---|
| 4 | * EC-CUBE データ生成スクリプト |
|---|
| 5 | * |
|---|
| 6 | * Copyright(c) 2000-2008 LOCKON CO.,LTD. All Rights Reserved. |
|---|
| 7 | * |
|---|
| 8 | * http://www.lockon.co.jp/ |
|---|
| 9 | * |
|---|
| 10 | * This program is free software; you can redistribute it and/or |
|---|
| 11 | * modify it under the terms of the GNU General Public License |
|---|
| 12 | * as published by the Free Software Foundation; either version 2 |
|---|
| 13 | * of the License, or (at your option) any later version. |
|---|
| 14 | * |
|---|
| 15 | * This program is distributed in the hope that it will be useful, |
|---|
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 18 | * GNU General Public License for more details. |
|---|
| 19 | * |
|---|
| 20 | * You should have received a copy of the GNU General Public License |
|---|
| 21 | * along with this program; if not, write to the Free Software |
|---|
| 22 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|---|
| 23 | * |
|---|
| 24 | * @auther Kentaro Ohkouchi |
|---|
| 25 | * @version $Id$ |
|---|
| 26 | */ |
|---|
| 27 | |
|---|
| 28 | // {{{ requires |
|---|
| 29 | require_once("DB.php"); |
|---|
| 30 | |
|---|
| 31 | // }}} |
|---|
| 32 | // {{{ constants |
|---|
| 33 | |
|---|
| 34 | /** データベース種別 */ |
|---|
| 35 | define("DB_TYPE", "pgsql"); |
|---|
| 36 | /** DBホスト */ |
|---|
| 37 | define("DB_SERVER", "localhost"); |
|---|
| 38 | /** DBポート */ |
|---|
| 39 | define("DB_PORT", "5432"); |
|---|
| 40 | /** DB名 */ |
|---|
| 41 | define("DB_NAME", "eccube_db"); |
|---|
| 42 | /** DBユーザー */ |
|---|
| 43 | define("DB_USER", "eccube_db_user"); |
|---|
| 44 | /** DBパスワード */ |
|---|
| 45 | define("DB_PASSWORD", "password"); |
|---|
| 46 | |
|---|
| 47 | /** データソース名 */ |
|---|
| 48 | define ("DEFAULT_DSN", |
|---|
| 49 | DB_TYPE . "://" . DB_USER . ":" . DB_PASSWORD . "@" |
|---|
| 50 | . DB_SERVER . ":" .DB_PORT . "/" . DB_NAME); |
|---|
| 51 | |
|---|
| 52 | /** 大カテゴリの生成数 */ |
|---|
| 53 | define("TOP_CATEGORIES_VOLUME", 5); |
|---|
| 54 | |
|---|
| 55 | /** 中カテゴリの生成数 */ |
|---|
| 56 | define("MIDDLE_CATEGORIES_VOLUME", 2); |
|---|
| 57 | |
|---|
| 58 | /** 小カテゴリの生成数 */ |
|---|
| 59 | define("SMALL_CATEGORIES_VOLUME", 3); |
|---|
| 60 | |
|---|
| 61 | /** 規格1の生成数 */ |
|---|
| 62 | define("CLASSCATEGORY1_VOLUME", 1); |
|---|
| 63 | |
|---|
| 64 | /** 規格2の生成数 */ |
|---|
| 65 | define("CLASSCATEGORY2_VOLUME", 2); |
|---|
| 66 | |
|---|
| 67 | /** 商品の生成数 */ |
|---|
| 68 | define("PRODUCTS_VOLUME", 100); |
|---|
| 69 | |
|---|
| 70 | // }}} |
|---|
| 71 | // {{{ Logic |
|---|
| 72 | |
|---|
| 73 | $objData = new CreateEcCubeData(); |
|---|
| 74 | $start = microtime(true); |
|---|
| 75 | $objData->objQuery->begin(); |
|---|
| 76 | |
|---|
| 77 | // カテゴリ生成 |
|---|
| 78 | $objData->createCategories(); |
|---|
| 79 | // 規格生成 |
|---|
| 80 | $objData->createClassData(); |
|---|
| 81 | // 商品生成 |
|---|
| 82 | $objData->createProducts(); |
|---|
| 83 | // 商品と規格の関連づけ |
|---|
| 84 | $objData->relateClass(); |
|---|
| 85 | // 商品とカテゴリの関連づけ |
|---|
| 86 | $objData->relateProductsCategories(); |
|---|
| 87 | //$objData->objQuery->rollback(); |
|---|
| 88 | $objData->objQuery->commit(); |
|---|
| 89 | $end = microtime(true); |
|---|
| 90 | print("データの生成が完了しました!\n"); |
|---|
| 91 | printf("所要時間 %f 秒\n", $end - $start); |
|---|
| 92 | |
|---|
| 93 | |
|---|
| 94 | // }}} |
|---|
| 95 | // {{{ classes |
|---|
| 96 | |
|---|
| 97 | /** |
|---|
| 98 | * EC-CUBE のデータを生成する |
|---|
| 99 | */ |
|---|
| 100 | class CreateEcCubeData { |
|---|
| 101 | |
|---|
| 102 | /** SC_Query インスタンス */ |
|---|
| 103 | var $objQuery; |
|---|
| 104 | |
|---|
| 105 | /** 大カテゴリID の配列 */ |
|---|
| 106 | var $arrCategory1 = array(); |
|---|
| 107 | |
|---|
| 108 | /** 中カテゴリID の配列 */ |
|---|
| 109 | var $arrCategory2 = array(); |
|---|
| 110 | |
|---|
| 111 | /** 小カテゴリID の配列 */ |
|---|
| 112 | var $arrCategory3 = array(); |
|---|
| 113 | |
|---|
| 114 | /** 規格1 */ |
|---|
| 115 | var $arrClassCategory_id1 = array(); |
|---|
| 116 | |
|---|
| 117 | /** 規格2 */ |
|---|
| 118 | var $arrClassCategory_id2 = array(); |
|---|
| 119 | |
|---|
| 120 | /** |
|---|
| 121 | * コンストラクタ. |
|---|
| 122 | */ |
|---|
| 123 | function CreateEcCubeData() { |
|---|
| 124 | $this->objQuery = new SC_Query(); |
|---|
| 125 | } |
|---|
| 126 | |
|---|
| 127 | /** |
|---|
| 128 | * カテゴリを生成する. |
|---|
| 129 | * |
|---|
| 130 | * 以下のように, ツリー状のカテゴリを生成する |
|---|
| 131 | * |
|---|
| 132 | * 大カテゴリ -- 中カテゴリ -- 小カテゴリ |
|---|
| 133 | * | |- 小カテゴリ |
|---|
| 134 | * | |- 小カテゴリ |
|---|
| 135 | * | |
|---|
| 136 | * |- 中カテゴリ -- 小カテゴリ |
|---|
| 137 | * |- 小カテゴリ |
|---|
| 138 | * |- 小カテゴリ |
|---|
| 139 | * @return void |
|---|
| 140 | */ |
|---|
| 141 | function createCategories() { |
|---|
| 142 | |
|---|
| 143 | print("カテゴリを生成しています...\n"); |
|---|
| 144 | |
|---|
| 145 | $count = 0; |
|---|
| 146 | |
|---|
| 147 | // 全カテゴリ共通の値 |
|---|
| 148 | $sqlval['creator_id'] = 2; |
|---|
| 149 | $sqlval['create_date'] = "now()"; |
|---|
| 150 | $sqlval['update_date'] = "now()"; |
|---|
| 151 | $sqlval['del_flg'] = (string) "0"; |
|---|
| 152 | |
|---|
| 153 | // 大カテゴリを生成 |
|---|
| 154 | for ($i = 0; $i < TOP_CATEGORIES_VOLUME; $i++) { |
|---|
| 155 | $sqlval['category_name'] = sprintf("Category%d00", $i); |
|---|
| 156 | $sqlval['parent_category_id'] = (string) "0"; |
|---|
| 157 | $sqlval['level'] = 1; |
|---|
| 158 | $sqlval['rank'] = $count; |
|---|
| 159 | |
|---|
| 160 | $this->objQuery->insert("dtb_category", $sqlval); |
|---|
| 161 | $category_id1 = $this->objQuery->currval("dtb_category", |
|---|
| 162 | "category_id"); |
|---|
| 163 | $this->arrCategory1[] = $category_id1; |
|---|
| 164 | $count++; |
|---|
| 165 | print("."); |
|---|
| 166 | |
|---|
| 167 | // 中カテゴリを生成 |
|---|
| 168 | for ($j = 0; $j < MIDDLE_CATEGORIES_VOLUME; $j++) { |
|---|
| 169 | $sqlval['category_name'] = sprintf("Category%d%d0", $i, |
|---|
| 170 | $j + MIDDLE_CATEGORIES_VOLUME); |
|---|
| 171 | $sqlval['parent_category_id'] = (string) $category_id1; |
|---|
| 172 | $sqlval['level'] = 2; |
|---|
| 173 | $sqlval['rank'] = $count; |
|---|
| 174 | |
|---|
| 175 | $this->objQuery->insert("dtb_category", $sqlval); |
|---|
| 176 | $category_id2 = $this->objQuery->currval("dtb_category", |
|---|
| 177 | "category_id"); |
|---|
| 178 | $this->arrCategory2[] = $category_id2; |
|---|
| 179 | $count++; |
|---|
| 180 | print("."); |
|---|
| 181 | |
|---|
| 182 | // 小カテゴリを生成 |
|---|
| 183 | for ($k = 0; $k < SMALL_CATEGORIES_VOLUME; $k++) { |
|---|
| 184 | $sqlval['category_name'] = sprintf("Category%d%d%d", |
|---|
| 185 | $i, $j, |
|---|
| 186 | $k + SMALL_CATEGORIES_VOLUME); |
|---|
| 187 | $sqlval['parent_category_id'] = (string) $category_id2; |
|---|
| 188 | $sqlval['level'] = 3; |
|---|
| 189 | $sqlval['rank'] = $count; |
|---|
| 190 | |
|---|
| 191 | $this->objQuery->insert("dtb_category", $sqlval); |
|---|
| 192 | $category_id3 = $this->objQuery->currval("dtb_category", |
|---|
| 193 | "category_id"); |
|---|
| 194 | $this->arrCategory3[] = $category_id3; |
|---|
| 195 | $count++; |
|---|
| 196 | print("."); |
|---|
| 197 | } |
|---|
| 198 | } |
|---|
| 199 | } |
|---|
| 200 | print("\n"); |
|---|
| 201 | } |
|---|
| 202 | |
|---|
| 203 | /** |
|---|
| 204 | * 規格を生成する. |
|---|
| 205 | * |
|---|
| 206 | * @return void |
|---|
| 207 | */ |
|---|
| 208 | function createClassData() { |
|---|
| 209 | // 規格データ生成 |
|---|
| 210 | print("規格データを生成しています...\n"); |
|---|
| 211 | $this->createClass("Size"); |
|---|
| 212 | $this->createClass("Color"); |
|---|
| 213 | print("\n"); |
|---|
| 214 | |
|---|
| 215 | // 規格分類データ生成 |
|---|
| 216 | print("規格分類データを生成しています...\n"); |
|---|
| 217 | |
|---|
| 218 | // 規格1 |
|---|
| 219 | for ($i = 0; $i < CLASSCATEGORY1_VOLUME; $i++) { |
|---|
| 220 | $this->createClassCategory($this->arrSize[$i], |
|---|
| 221 | $this->arrclass_id[0], "size"); |
|---|
| 222 | } |
|---|
| 223 | |
|---|
| 224 | // 規格2 |
|---|
| 225 | for ($i = 0; $i < CLASSCATEGORY2_VOLUME; $i++) { |
|---|
| 226 | $this->createClassCategory($this->arrSize[$i], |
|---|
| 227 | $this->arrclass_id[1], "color"); |
|---|
| 228 | } |
|---|
| 229 | |
|---|
| 230 | print("\n"); |
|---|
| 231 | } |
|---|
| 232 | |
|---|
| 233 | /** |
|---|
| 234 | * 商品と規格の関連づけを行う. |
|---|
| 235 | * |
|---|
| 236 | * @return void |
|---|
| 237 | */ |
|---|
| 238 | function relateClass() { |
|---|
| 239 | |
|---|
| 240 | print("商品と規格の関連づけを行います...\n"); |
|---|
| 241 | |
|---|
| 242 | foreach ($this->arrProduct_id as $product_id) { |
|---|
| 243 | $this->createProductsClass($product_id); |
|---|
| 244 | } |
|---|
| 245 | print("\n"); |
|---|
| 246 | } |
|---|
| 247 | |
|---|
| 248 | /** |
|---|
| 249 | * 商品を生成する. |
|---|
| 250 | * |
|---|
| 251 | * @return void |
|---|
| 252 | */ |
|---|
| 253 | function createProducts() { |
|---|
| 254 | |
|---|
| 255 | print("商品を生成しています...\n"); |
|---|
| 256 | for ($i = 0; $i < PRODUCTS_VOLUME; $i++) { |
|---|
| 257 | $sqlval['name'] = sprintf("商品%d", $i); |
|---|
| 258 | $sqlval['status'] = 1; |
|---|
| 259 | $sqlval['product_flag'] = "10010"; |
|---|
| 260 | $sqlval['point_rate'] = 1; |
|---|
| 261 | $sqlval['comment3'] = "コメント"; |
|---|
| 262 | $sqlval['main_list_comment'] = "コメント"; |
|---|
| 263 | $sqlval['main_list_image'] = "08311201_44f65122ee5fe.jpg"; |
|---|
| 264 | $sqlval['main_comment'] = "コメント"; |
|---|
| 265 | $sqlval['main_image'] = "08311202_44f6515906a41.jpg"; |
|---|
| 266 | $sqlval['main_large_image'] = "08311203_44f651959bcb5.jpg"; |
|---|
| 267 | $sqlval['sub_comment1'] = "コメント"; |
|---|
| 268 | $sqlval['del_flg'] = (string) "0"; |
|---|
| 269 | $sqlval['creator_id'] = 2; |
|---|
| 270 | $sqlval['create_date'] = "now()"; |
|---|
| 271 | $sqlval['update_date'] = "now()"; |
|---|
| 272 | $sqlval['deliv_date_id'] = 2; |
|---|
| 273 | |
|---|
| 274 | $this->objQuery->insert("dtb_products", $sqlval); |
|---|
| 275 | $this->arrProduct_id[] = $this->objQuery->currval("dtb_products", |
|---|
| 276 | "product_id"); |
|---|
| 277 | print("*"); |
|---|
| 278 | } |
|---|
| 279 | } |
|---|
| 280 | |
|---|
| 281 | /** |
|---|
| 282 | * 規格を生成する. |
|---|
| 283 | * |
|---|
| 284 | * @param $class_name string 規格名 |
|---|
| 285 | * @return void |
|---|
| 286 | */ |
|---|
| 287 | function createClass($class_name) { |
|---|
| 288 | $sqlval['name'] = $class_name; |
|---|
| 289 | $sqlval['status'] = null; |
|---|
| 290 | $sqlval['rank'] = "~(SELECT CASE |
|---|
| 291 | WHEN max(rank) + 1 IS NULL THEN 1 |
|---|
| 292 | ELSE max(rank) + 1 |
|---|
| 293 | END |
|---|
| 294 | FROM dtb_class |
|---|
| 295 | WHERE del_flg = 0),"; |
|---|
| 296 | $sqlval['creator_id'] = 2; |
|---|
| 297 | $sqlval['update_date'] = "now()"; |
|---|
| 298 | $sqlval['del_flg'] = (string) "0"; |
|---|
| 299 | $sqlval['product_id'] = null; |
|---|
| 300 | |
|---|
| 301 | $this->objQuery->insert("dtb_class", $sqlval); |
|---|
| 302 | |
|---|
| 303 | // class_idを取得 |
|---|
| 304 | $this->arrclass_id[] = $this->objQuery->currval("dtb_class", "class_id"); |
|---|
| 305 | print("+"); |
|---|
| 306 | } |
|---|
| 307 | |
|---|
| 308 | /** |
|---|
| 309 | * 規格分類を生成する. |
|---|
| 310 | * |
|---|
| 311 | * @param $classcategory_name string 規格名 |
|---|
| 312 | * @return void |
|---|
| 313 | */ |
|---|
| 314 | function createClassCategory($classcategory_name, $class_id, $class_name) { |
|---|
| 315 | $sqlval['name'] = $classcategory_name; |
|---|
| 316 | $sqlval['class_id'] = $class_id; |
|---|
| 317 | $sqlval['status'] = null; |
|---|
| 318 | $sqlval['rank'] = sprintf("~(SELECT CASE |
|---|
| 319 | WHEN max(rank) + 1 IS NULL THEN 1 |
|---|
| 320 | ELSE max(rank) + 1 |
|---|
| 321 | END |
|---|
| 322 | FROM dtb_classcategory |
|---|
| 323 | WHERE del_flg = 0 |
|---|
| 324 | AND class_id = %d),", $class_id); |
|---|
| 325 | $sqlval['creator_id'] = 2; |
|---|
| 326 | $sqlval['create_date'] = "now()"; |
|---|
| 327 | $sqlval['update_date'] = "now()"; |
|---|
| 328 | $sqlval['del_flg'] = (string) "0"; |
|---|
| 329 | |
|---|
| 330 | $this->objQuery->insert("dtb_classcategory", $sqlval); |
|---|
| 331 | |
|---|
| 332 | switch ($class_name) { |
|---|
| 333 | case "size": |
|---|
| 334 | $this->arrClassCategory_id1[] = |
|---|
| 335 | $this->objQuery->currval("dtb_classcategory", |
|---|
| 336 | "classcategory_id"); |
|---|
| 337 | break; |
|---|
| 338 | |
|---|
| 339 | case "color": |
|---|
| 340 | $this->arrClassCategory_id2[] = |
|---|
| 341 | $this->objQuery->currval("dtb_classcategory", |
|---|
| 342 | "classcategory_id"); |
|---|
| 343 | break; |
|---|
| 344 | default: |
|---|
| 345 | } |
|---|
| 346 | print("+"); |
|---|
| 347 | } |
|---|
| 348 | |
|---|
| 349 | /** |
|---|
| 350 | * 商品規格を生成する. |
|---|
| 351 | * |
|---|
| 352 | * @param integer $product_id 商品ID |
|---|
| 353 | * @return void |
|---|
| 354 | */ |
|---|
| 355 | function createProductsClass($product_id) { |
|---|
| 356 | |
|---|
| 357 | printf("商品ID %d の商品規格を生成しています...\n", $product_id); |
|---|
| 358 | |
|---|
| 359 | $sqlval['product_id'] = $product_id; |
|---|
| 360 | $sqlval['stock_unlimited'] = 1; |
|---|
| 361 | $sqlval['price01'] = 1000; |
|---|
| 362 | $sqlval['price02'] = 2000; |
|---|
| 363 | $sqlval['creator_id'] = 2; |
|---|
| 364 | $sqlval['create_date'] = "now()"; |
|---|
| 365 | $sqlval['update_date'] = "now()"; |
|---|
| 366 | |
|---|
| 367 | $count = 0; |
|---|
| 368 | foreach ($this->arrClassCategory_id1 as $classCategory_id1) { |
|---|
| 369 | $sqlval['classcategory_id1'] = $classCategory_id1; |
|---|
| 370 | |
|---|
| 371 | foreach ($this->arrClassCategory_id2 as $classCategory_id2) { |
|---|
| 372 | $sqlval['classcategory_id2'] = $classCategory_id2; |
|---|
| 373 | $sqlval['product_code'] = sprintf("商品コード%d", $count); |
|---|
| 374 | |
|---|
| 375 | $this->objQuery->insert("dtb_products_class", $sqlval); |
|---|
| 376 | $count++; |
|---|
| 377 | print("#"); |
|---|
| 378 | } |
|---|
| 379 | } |
|---|
| 380 | print("\n"); |
|---|
| 381 | } |
|---|
| 382 | |
|---|
| 383 | /** |
|---|
| 384 | * 商品とカテゴリの関連づけを行う. |
|---|
| 385 | * |
|---|
| 386 | * @return void |
|---|
| 387 | */ |
|---|
| 388 | function relateProductsCategories() { |
|---|
| 389 | |
|---|
| 390 | print("商品とカテゴリの関連づけを行います...\n"); |
|---|
| 391 | $this->createProductsCategories($this->arrCategory1, "大カテゴリ"); |
|---|
| 392 | $this->createProductsCategories($this->arrCategory2, "中カテゴリ"); |
|---|
| 393 | $this->createProductsCategories($this->arrCategory3, "小カテゴリ"); |
|---|
| 394 | } |
|---|
| 395 | |
|---|
| 396 | /** |
|---|
| 397 | * 商品カテゴリを生成する. |
|---|
| 398 | * |
|---|
| 399 | * @param array $arrCategory_id カテゴリID の配列 |
|---|
| 400 | * @return void |
|---|
| 401 | */ |
|---|
| 402 | function createProductsCategories($arrCategory_id, $category_name) { |
|---|
| 403 | |
|---|
| 404 | $count = 0; |
|---|
| 405 | printf("%s の商品カテゴリを生成しています...\n", $category_name); |
|---|
| 406 | foreach ($arrCategory_id as $category_id) { |
|---|
| 407 | $sqlval['category_id'] = $category_id; |
|---|
| 408 | |
|---|
| 409 | foreach($this->arrProduct_id as $product_id) { |
|---|
| 410 | $sqlval['product_id'] = $product_id; |
|---|
| 411 | $sqlval['rank'] = $count; |
|---|
| 412 | |
|---|
| 413 | $this->objQuery->insert("dtb_product_categories", $sqlval); |
|---|
| 414 | $count++; |
|---|
| 415 | print("$"); |
|---|
| 416 | } |
|---|
| 417 | } |
|---|
| 418 | print("\n"); |
|---|
| 419 | } |
|---|
| 420 | |
|---|
| 421 | /** 規格1 */ |
|---|
| 422 | var $arrSize = array("m11(29cm)" |
|---|
| 423 | ,"m10 1/2(28.5cm)" |
|---|
| 424 | ,"m10(28cm)" |
|---|
| 425 | ,"m9 1/2(27.5cm)" |
|---|
| 426 | ,"m9(27cm)" |
|---|
| 427 | ,"m8 1/2(26.5cm)" |
|---|
| 428 | ,"m8(26cm)" |
|---|
| 429 | ,"43" |
|---|
| 430 | ,"42" |
|---|
| 431 | ,"41" |
|---|
| 432 | ,"43(27.0cm?27.5cm)" |
|---|
| 433 | ,"42(26.5cm?27.0cm)" |
|---|
| 434 | ,"37(ladies 23.5?24cm)" |
|---|
| 435 | ,"42(約27.5cm)" |
|---|
| 436 | ,"41(約26.5cm)" |
|---|
| 437 | ,"W36" |
|---|
| 438 | ,"W34" |
|---|
| 439 | ,"W32" |
|---|
| 440 | ,"43" |
|---|
| 441 | ,"42" |
|---|
| 442 | ,"41" |
|---|
| 443 | ,"m11" |
|---|
| 444 | ,"m10" |
|---|
| 445 | ,"m9.5" |
|---|
| 446 | ,"m9" |
|---|
| 447 | ,"m8" |
|---|
| 448 | ,"FREE" |
|---|
| 449 | ,"XS" |
|---|
| 450 | ,"S" |
|---|
| 451 | ,"M" |
|---|
| 452 | ,"L" |
|---|
| 453 | ,"XL" |
|---|
| 454 | ,"25-27" |
|---|
| 455 | ,"27-29" |
|---|
| 456 | ,"W28" |
|---|
| 457 | ,"W29" |
|---|
| 458 | ,"W30" |
|---|
| 459 | ,"W31" |
|---|
| 460 | ,"W32" |
|---|
| 461 | ,"W33" |
|---|
| 462 | ,"W34" |
|---|
| 463 | ,"W35" |
|---|
| 464 | ,"W36" |
|---|
| 465 | ,"4" |
|---|
| 466 | ,"6" |
|---|
| 467 | ,"8" |
|---|
| 468 | ,"10" |
|---|
| 469 | ,"12" |
|---|
| 470 | ,"10cm" |
|---|
| 471 | ,"12cm" |
|---|
| 472 | ,"14cm" |
|---|
| 473 | ,"16cm" |
|---|
| 474 | ,"18cm" |
|---|
| 475 | ,"20cm" |
|---|
| 476 | ,"22cm" |
|---|
| 477 | ,"24cm" |
|---|
| 478 | ,"26cm" |
|---|
| 479 | ,"28cm" |
|---|
| 480 | ,"30cm" |
|---|
| 481 | ,"32cm" |
|---|
| 482 | ,"34cm" |
|---|
| 483 | ,"36cm" |
|---|
| 484 | ,"38cm" |
|---|
| 485 | ,"40cm" |
|---|
| 486 | ,"10g" |
|---|
| 487 | ,"20g" |
|---|
| 488 | ,"30g" |
|---|
| 489 | ,"40g" |
|---|
| 490 | ,"50g" |
|---|
| 491 | ,"60g" |
|---|
| 492 | ,"70g" |
|---|
| 493 | ,"80g" |
|---|
| 494 | ,"90g" |
|---|
| 495 | ,"100g" |
|---|
| 496 | ,"110g" |
|---|
| 497 | ,"120g" |
|---|
| 498 | ,"130g" |
|---|
| 499 | ,"140g" |
|---|
| 500 | ,"150g" |
|---|
| 501 | ,"160g" |
|---|
| 502 | ,"170g" |
|---|
| 503 | ,"180g" |
|---|
| 504 | ,"190g" |
|---|
| 505 | ,"200g" |
|---|
| 506 | ,"8inch" |
|---|
| 507 | ,"10inch" |
|---|
| 508 | ,"12inch" |
|---|
| 509 | ,"14inch" |
|---|
| 510 | ,"16inch" |
|---|
| 511 | ,"18inch" |
|---|
| 512 | ,"20inch" |
|---|
| 513 | ,"22inch" |
|---|
| 514 | ,"24inch" |
|---|
| 515 | ,"26inch" |
|---|
| 516 | ,"28inch" |
|---|
| 517 | ,"30inch" |
|---|
| 518 | ,"32inch" |
|---|
| 519 | ,"34inch" |
|---|
| 520 | ,"36inch" |
|---|
| 521 | ,"38inch" |
|---|
| 522 | ); |
|---|
| 523 | |
|---|
| 524 | /** 規格2 */ |
|---|
| 525 | var $arrColor = array("white" |
|---|
| 526 | ,"whitesmoke" |
|---|
| 527 | ,"snow" |
|---|
| 528 | ,"ghostwhite" |
|---|
| 529 | ,"mintcream" |
|---|
| 530 | ,"azure" |
|---|
| 531 | ,"ivory" |
|---|
| 532 | ,"floralwhite" |
|---|
| 533 | ,"aliceblue" |
|---|
| 534 | ,"lavenderblush" |
|---|
| 535 | ,"seashell" |
|---|
| 536 | ,"honeydew" |
|---|
| 537 | ,"lightyellow" |
|---|
| 538 | ,"oldlace" |
|---|
| 539 | ,"cornsilk" |
|---|
| 540 | ,"linen" |
|---|
| 541 | ,"lemonchiffon" |
|---|
| 542 | ,"lavender" |
|---|
| 543 | ,"beige" |
|---|
| 544 | ,"lightgoldenrodyellow" |
|---|
| 545 | ,"mistyrose" |
|---|
| 546 | ,"papayawhip" |
|---|
| 547 | ,"antiquewhite" |
|---|
| 548 | ,"lightcyan" |
|---|
| 549 | ,"cyan" |
|---|
| 550 | ,"aqua" |
|---|
| 551 | ,"darkcyan" |
|---|
| 552 | ,"teal" |
|---|
| 553 | ,"darkslategray" |
|---|
| 554 | ,"turquoise" |
|---|
| 555 | ,"paleturquoise" |
|---|
| 556 | ,"mediumturquoise" |
|---|
| 557 | ,"aquamarine" |
|---|
| 558 | ,"gainsboro" |
|---|
| 559 | ,"lightgray" |
|---|
| 560 | ,"silver" |
|---|
| 561 | ,"darkgray" |
|---|
| 562 | ,"gray" |
|---|
| 563 | ,"dimgray" |
|---|
| 564 | ,"black" |
|---|
| 565 | ,"powderblue" |
|---|
| 566 | ,"lightblue" |
|---|
| 567 | ,"lightskyblue" |
|---|
| 568 | ,"skyblue" |
|---|
| 569 | ,"darkturquoise" |
|---|
| 570 | ,"deepskyblue" |
|---|
| 571 | ,"dodgerblue" |
|---|
| 572 | ,"royalblue" |
|---|
| 573 | ,"cornflowerblue" |
|---|
| 574 | ,"cadetblue" |
|---|
| 575 | ,"lightsteelblue" |
|---|
| 576 | ,"steelblue" |
|---|
| 577 | ,"lightslategray" |
|---|
| 578 | ,"slategray" |
|---|
| 579 | ,"blue" |
|---|
| 580 | ,"mediumblue" |
|---|
| 581 | ,"darkblue" |
|---|
| 582 | ,"navy" |
|---|
| 583 | ,"midnightblue" |
|---|
| 584 | ,"lightsalmon" |
|---|
| 585 | ,"darksalmon" |
|---|
| 586 | ,"salmon" |
|---|
| 587 | ,"tomato" |
|---|
| 588 | ,"lightcoral" |
|---|
| 589 | ,"coral" |
|---|
| 590 | ,"crimson" |
|---|
| 591 | ,"red" |
|---|
| 592 | ,"mediumorchid" |
|---|
| 593 | ,"mediumpurple" |
|---|
| 594 | ,"mediumslateblue" |
|---|
| 595 | ,"slateblue" |
|---|
| 596 | ,"blueviolet" |
|---|
| 597 | ,"darkviolet" |
|---|
| 598 | ,"darkorchid" |
|---|
| 599 | ,"darkslateblue" |
|---|
| 600 | ,"darkorchid" |
|---|
| 601 | ,"thistle" |
|---|
| 602 | ,"plum" |
|---|
| 603 | ,"violet" |
|---|
| 604 | ,"magenta" |
|---|
| 605 | ,"fuchsia" |
|---|
| 606 | ,"darkmagenta" |
|---|
| 607 | ,"purple" |
|---|
| 608 | ,"palegreen" |
|---|
| 609 | ,"lightgreen" |
|---|
| 610 | ,"lime" |
|---|
| 611 | ,"limegreen" |
|---|
| 612 | ,"forestgreen" |
|---|
| 613 | ,"green" |
|---|
| 614 | ,"darkgreen" |
|---|
| 615 | ,"greenyellow" |
|---|
| 616 | ,"chartreuse" |
|---|
| 617 | ,"lawngreen" |
|---|
| 618 | ,"yellowgreen" |
|---|
| 619 | ,"olivedrab" |
|---|
| 620 | ,"darkolivegreen" |
|---|
| 621 | ,"mediumaquamarine" |
|---|
| 622 | ,"mediumspringgreen" |
|---|
| 623 | ,"springgreen" |
|---|
| 624 | ,"darkseagreen" |
|---|
| 625 | ); |
|---|
| 626 | |
|---|
| 627 | } |
|---|
| 628 | |
|---|
| 629 | /** |
|---|
| 630 | * クエリを生成して実行する. |
|---|
| 631 | * |
|---|
| 632 | * (EC-CUBE からの移植) |
|---|
| 633 | */ |
|---|
| 634 | class SC_Query { |
|---|
| 635 | var $option; |
|---|
| 636 | var $where; |
|---|
| 637 | var $conn; |
|---|
| 638 | var $groupby; |
|---|
| 639 | var $order; |
|---|
| 640 | |
|---|
| 641 | // コンストラクタ |
|---|
| 642 | /* |
|---|
| 643 | $err_disp:エラー表示を行うか |
|---|
| 644 | $new:新規に接続を行うか |
|---|
| 645 | */ |
|---|
| 646 | function SC_Query($dsn = "", $err_disp = true, $new = false) { |
|---|
| 647 | $this->conn = new SC_DbConn($dsn, $err_disp, $new); |
|---|
| 648 | $this->where = ""; |
|---|
| 649 | return $this->conn; |
|---|
| 650 | } |
|---|
| 651 | |
|---|
| 652 | // エラー判定 |
|---|
| 653 | function isError() { |
|---|
| 654 | if(PEAR::isError($this->conn->conn)) { |
|---|
| 655 | return true; |
|---|
| 656 | } |
|---|
| 657 | return false; |
|---|
| 658 | } |
|---|
| 659 | |
|---|
| 660 | // COUNT文の実行 |
|---|
| 661 | function count($table, $where = "", $arrval = array()) { |
|---|
| 662 | if(strlen($where) <= 0) { |
|---|
| 663 | $sqlse = "SELECT COUNT(*) FROM $table"; |
|---|
| 664 | } else { |
|---|
| 665 | $sqlse = "SELECT COUNT(*) FROM $table WHERE $where"; |
|---|
| 666 | } |
|---|
| 667 | // カウント文の実行 |
|---|
| 668 | $ret = $this->conn->getOne($sqlse, $arrval); |
|---|
| 669 | return $ret; |
|---|
| 670 | } |
|---|
| 671 | |
|---|
| 672 | function select($col, $table, $where = "", $arrval = array()){ |
|---|
| 673 | $sqlse = $this->getsql($col, $table, $where); |
|---|
| 674 | // DBに依存した SQL へ変換 |
|---|
| 675 | $dbFactory = SC_DB_DBFactory::getInstance(); |
|---|
| 676 | $sqlse = $dbFactory->sfChangeMySQL($sqlse); |
|---|
| 677 | $ret = $this->conn->getAll($sqlse, $arrval); |
|---|
| 678 | return $ret; |
|---|
| 679 | } |
|---|
| 680 | |
|---|
| 681 | function getLastQuery($disp = true) { |
|---|
| 682 | $sql = $this->conn->conn->last_query; |
|---|
| 683 | if($disp) { |
|---|
| 684 | print($sql.";<br />\n"); |
|---|
| 685 | } |
|---|
| 686 | return $sql; |
|---|
| 687 | } |
|---|
| 688 | |
|---|
| 689 | function commit() { |
|---|
| 690 | $this->conn->query("COMMIT"); |
|---|
| 691 | } |
|---|
| 692 | |
|---|
| 693 | function begin() { |
|---|
| 694 | $this->conn->query("BEGIN"); |
|---|
| 695 | } |
|---|
| 696 | |
|---|
| 697 | function rollback() { |
|---|
| 698 | $this->conn->query("ROLLBACK"); |
|---|
| 699 | } |
|---|
| 700 | |
|---|
| 701 | function exec($str, $arrval = array()) { |
|---|
| 702 | $this->conn->query($str, $arrval); |
|---|
| 703 | } |
|---|
| 704 | |
|---|
| 705 | function autoselect($col, $table, $arrwhere = array(), $arrcon = array()) { |
|---|
| 706 | $strw = ""; |
|---|
| 707 | $find = false; |
|---|
| 708 | foreach ($arrwhere as $key => $val) { |
|---|
| 709 | if(strlen($val) > 0) { |
|---|
| 710 | if(strlen($strw) <= 0) { |
|---|
| 711 | $strw .= $key ." LIKE ?"; |
|---|
| 712 | } else if(strlen($arrcon[$key]) > 0) { |
|---|
| 713 | $strw .= " ". $arrcon[$key]. " " . $key ." LIKE ?"; |
|---|
| 714 | } else { |
|---|
| 715 | $strw .= " AND " . $key ." LIKE ?"; |
|---|
| 716 | } |
|---|
| 717 | |
|---|
| 718 | $arrval[] = $val; |
|---|
| 719 | } |
|---|
| 720 | } |
|---|
| 721 | |
|---|
| 722 | if(strlen($strw) > 0) { |
|---|
| 723 | $sqlse = "SELECT $col FROM $table WHERE $strw ".$this->option; |
|---|
| 724 | } else { |
|---|
| 725 | $sqlse = "SELECT $col FROM $table ".$this->option; |
|---|
| 726 | } |
|---|
| 727 | $ret = $this->conn->getAll($sqlse, $arrval); |
|---|
| 728 | return $ret; |
|---|
| 729 | } |
|---|
| 730 | |
|---|
| 731 | function getall($sql, $arrval = array()) { |
|---|
| 732 | $ret = $this->conn->getAll($sql, $arrval); |
|---|
| 733 | return $ret; |
|---|
| 734 | } |
|---|
| 735 | |
|---|
| 736 | function getsql($col, $table, $where) { |
|---|
| 737 | if($where != "") { |
|---|
| 738 | // 引数の$whereを優先して実行する。 |
|---|
| 739 | $sqlse = "SELECT $col FROM $table WHERE $where " . $this->groupby . " " . $this->order . " " . $this->option; |
|---|
| 740 | } else { |
|---|
| 741 | if($this->where != "") { |
|---|
| 742 | $sqlse = "SELECT $col FROM $table WHERE $this->where " . $this->groupby . " " . $this->order . " " . $this->option; |
|---|
| 743 | } else { |
|---|
| 744 | $sqlse = "SELECT $col FROM $table " . $this->groupby . " " . $this->order . " " . $this->option; |
|---|
| 745 | } |
|---|
| 746 | } |
|---|
| 747 | return $sqlse; |
|---|
| 748 | } |
|---|
| 749 | |
|---|
| 750 | function setoption($str) { |
|---|
| 751 | $this->option = $str; |
|---|
| 752 | } |
|---|
| 753 | |
|---|
| 754 | function setlimitoffset($limit, $offset = 0, $return = false) { |
|---|
| 755 | if (is_numeric($limit) && is_numeric($offset)){ |
|---|
| 756 | |
|---|
| 757 | $option = " LIMIT " . $limit; |
|---|
| 758 | $option.= " OFFSET " . $offset; |
|---|
| 759 | |
|---|
| 760 | if($return){ |
|---|
| 761 | return $option; |
|---|
| 762 | }else{ |
|---|
| 763 | $this->option.= $option; |
|---|
| 764 | } |
|---|
| 765 | } |
|---|
| 766 | } |
|---|
| 767 | |
|---|
| 768 | function setgroupby($str) { |
|---|
| 769 | $this->groupby = "GROUP BY " . $str; |
|---|
| 770 | } |
|---|
| 771 | |
|---|
| 772 | function andwhere($str) { |
|---|
| 773 | if($this->where != "") { |
|---|
| 774 | $this->where .= " AND " . $str; |
|---|
| 775 | } else { |
|---|
| 776 | $this->where = $str; |
|---|
| 777 | } |
|---|
| 778 | } |
|---|
| 779 | |
|---|
| 780 | function orwhere($str) { |
|---|
| 781 | if($this->where != "") { |
|---|
| 782 | $this->where .= " OR " . $str; |
|---|
| 783 | } else { |
|---|
| 784 | $this->where = $str; |
|---|
| 785 | } |
|---|
| 786 | } |
|---|
| 787 | |
|---|
| 788 | function setwhere($str) { |
|---|
| 789 | $this->where = $str; |
|---|
| 790 | } |
|---|
| 791 | |
|---|
| 792 | function setorder($str) { |
|---|
| 793 | $this->order = "ORDER BY " . $str; |
|---|
| 794 | } |
|---|
| 795 | |
|---|
| 796 | |
|---|
| 797 | function setlimit($limit){ |
|---|
| 798 | if ( is_numeric($limit)){ |
|---|
| 799 | $this->option = " LIMIT " .$limit; |
|---|
| 800 | } |
|---|
| 801 | } |
|---|
| 802 | |
|---|
| 803 | function setoffset($offset) { |
|---|
| 804 | if ( is_numeric($offset)){ |
|---|
| 805 | $this->offset = " OFFSET " .$offset; |
|---|
| 806 | } |
|---|
| 807 | } |
|---|
| 808 | |
|---|
| 809 | |
|---|
| 810 | // INSERT文の生成・実行 |
|---|
| 811 | // $table :テーブル名 |
|---|
| 812 | // $sqlval :列名 => 値の格納されたハッシュ配列 |
|---|
| 813 | function insert($table, $sqlval) { |
|---|
| 814 | $strcol = ''; |
|---|
| 815 | $strval = ''; |
|---|
| 816 | $find = false; |
|---|
| 817 | |
|---|
| 818 | if(count($sqlval) <= 0 ) return false; |
|---|
| 819 | |
|---|
| 820 | foreach ($sqlval as $key => $val) { |
|---|
| 821 | $strcol .= $key . ','; |
|---|
| 822 | if(eregi("^Now\(\)$", $val)) { |
|---|
| 823 | $strval .= 'Now(),'; |
|---|
| 824 | // 先頭に~があるとプレースホルダーしない。 |
|---|
| 825 | } else if(ereg("^~", $val)) { |
|---|
| 826 | $strval .= ereg_replace("^~", "", $val); |
|---|
| 827 | } else { |
|---|
| 828 | $strval .= '?,'; |
|---|
| 829 | if($val != ""){ |
|---|
| 830 | $arrval[] = $val; |
|---|
| 831 | } else { |
|---|
| 832 | $arrval[] = NULL; |
|---|
| 833 | } |
|---|
| 834 | } |
|---|
| 835 | $find = true; |
|---|
| 836 | } |
|---|
| 837 | if(!$find) { |
|---|
| 838 | return false; |
|---|
| 839 | } |
|---|
| 840 | // 文末の","を削除 |
|---|
| 841 | $strcol = ereg_replace(",$","",$strcol); |
|---|
| 842 | // 文末の","を削除 |
|---|
| 843 | $strval = ereg_replace(",$","",$strval); |
|---|
| 844 | $sqlin = "INSERT INTO $table(" . $strcol. ") VALUES (" . $strval . ")"; |
|---|
| 845 | |
|---|
| 846 | // INSERT文の実行 |
|---|
| 847 | $ret = $this->conn->query($sqlin, $arrval); |
|---|
| 848 | |
|---|
| 849 | return $ret; |
|---|
| 850 | } |
|---|
| 851 | |
|---|
| 852 | // INSERT文の生成・実行 |
|---|
| 853 | // $table :テーブル名 |
|---|
| 854 | // $sqlval :列名 => 値の格納されたハッシュ配列 |
|---|
| 855 | function fast_insert($table, $sqlval) { |
|---|
| 856 | $strcol = ''; |
|---|
| 857 | $strval = ''; |
|---|
| 858 | $find = false; |
|---|
| 859 | |
|---|
| 860 | foreach ($sqlval as $key => $val) { |
|---|
| 861 | $strcol .= $key . ','; |
|---|
| 862 | if($val != ""){ |
|---|
| 863 | $eval = pg_escape_string($val); |
|---|
| 864 | $strval .= "'$eval',"; |
|---|
| 865 | } else { |
|---|
| 866 | $strval .= "NULL,"; |
|---|
| 867 | } |
|---|
| 868 | $find = true; |
|---|
| 869 | } |
|---|
| 870 | if(!$find) { |
|---|
| 871 | return false; |
|---|
| 872 | } |
|---|
| 873 | // 文末の","を削除 |
|---|
| 874 | $strcol = ereg_replace(",$","",$strcol); |
|---|
| 875 | // 文末の","を削除 |
|---|
| 876 | $strval = ereg_replace(",$","",$strval); |
|---|
| 877 | $sqlin = "INSERT INTO $table(" . $strcol. ") VALUES (" . $strval . ")"; |
|---|
| 878 | |
|---|
| 879 | // INSERT文の実行 |
|---|
| 880 | $ret = $this->conn->query($sqlin); |
|---|
| 881 | |
|---|
| 882 | return $ret; |
|---|
| 883 | } |
|---|
| 884 | |
|---|
| 885 | |
|---|
| 886 | // UPDATE文の生成・実行 |
|---|
| 887 | // $table :テーブル名 |
|---|
| 888 | // $sqlval :列名 => 値の格納されたハッシュ配列 |
|---|
| 889 | // $where :WHERE文字列 |
|---|
| 890 | function update($table, $sqlval, $where = "", $arradd = "", $addcol = "") { |
|---|
| 891 | $strcol = ''; |
|---|
| 892 | $strval = ''; |
|---|
| 893 | $find = false; |
|---|
| 894 | foreach ($sqlval as $key => $val) { |
|---|
| 895 | if(eregi("^Now\(\)$", $val)) { |
|---|
| 896 | $strcol .= $key . '= Now(),'; |
|---|
| 897 | // 先頭に~があるとプレースホルダーしない。 |
|---|
| 898 | } else if(ereg("^~", $val)) { |
|---|
| 899 | $strcol .= $key . "=" . ereg_replace("^~", "", $val) . ","; |
|---|
| 900 | } else { |
|---|
| 901 | $strcol .= $key . '= ?,'; |
|---|
| 902 | if($val != ""){ |
|---|
| 903 | $arrval[] = $val; |
|---|
| 904 | } else { |
|---|
| 905 | $arrval[] = NULL; |
|---|
| 906 | } |
|---|
| 907 | } |
|---|
| 908 | $find = true; |
|---|
| 909 | } |
|---|
| 910 | if(!$find) { |
|---|
| 911 | return false; |
|---|
| 912 | } |
|---|
| 913 | |
|---|
| 914 | if($addcol != "") { |
|---|
| 915 | foreach($addcol as $key => $val) { |
|---|
| 916 | $strcol .= "$key = $val,"; |
|---|
| 917 | } |
|---|
| 918 | } |
|---|
| 919 | |
|---|
| 920 | // 文末の","を削除 |
|---|
| 921 | $strcol = ereg_replace(",$","",$strcol); |
|---|
| 922 | // 文末の","を削除 |
|---|
| 923 | $strval = ereg_replace(",$","",$strval); |
|---|
| 924 | |
|---|
| 925 | if($where != "") { |
|---|
| 926 | $sqlup = "UPDATE $table SET $strcol WHERE $where"; |
|---|
| 927 | } else { |
|---|
| 928 | $sqlup = "UPDATE $table SET $strcol"; |
|---|
| 929 | } |
|---|
| 930 | |
|---|
| 931 | if(is_array($arradd)) { |
|---|
| 932 | // プレースホルダー用に配列を追加 |
|---|
| 933 | foreach($arradd as $val) { |
|---|
| 934 | $arrval[] = $val; |
|---|
| 935 | } |
|---|
| 936 | } |
|---|
| 937 | |
|---|
| 938 | // INSERT文の実行 |
|---|
| 939 | $ret = $this->conn->query($sqlup, $arrval); |
|---|
| 940 | return $ret; |
|---|
| 941 | } |
|---|
| 942 | |
|---|
| 943 | // MAX文の実行 |
|---|
| 944 | function max($table, $col, $where = "", $arrval = array()) { |
|---|
| 945 | if(strlen($where) <= 0) { |
|---|
| 946 | $sqlse = "SELECT MAX($col) FROM $table"; |
|---|
| 947 | } else { |
|---|
| 948 | $sqlse = "SELECT MAX($col) FROM $table WHERE $where"; |
|---|
| 949 | } |
|---|
| 950 | // MAX文の実行 |
|---|
| 951 | $ret = $this->conn->getOne($sqlse, $arrval); |
|---|
| 952 | return $ret; |
|---|
| 953 | } |
|---|
| 954 | |
|---|
| 955 | // MIN文の実行 |
|---|
| 956 | function min($table, $col, $where = "", $arrval = array()) { |
|---|
| 957 | if(strlen($where) <= 0) { |
|---|
| 958 | $sqlse = "SELECT MIN($col) FROM $table"; |
|---|
| 959 | } else { |
|---|
| 960 | $sqlse = "SELECT MIN($col) FROM $table WHERE $where"; |
|---|
| 961 | } |
|---|
| 962 | // MIN文の実行 |
|---|
| 963 | $ret = $this->conn->getOne($sqlse, $arrval); |
|---|
| 964 | return $ret; |
|---|
| 965 | } |
|---|
| 966 | |
|---|
| 967 | // 特定のカラムの値を取得 |
|---|
| 968 | function get($table, $col, $where = "", $arrval = array()) { |
|---|
| 969 | if(strlen($where) <= 0) { |
|---|
| 970 | $sqlse = "SELECT $col FROM $table"; |
|---|
| 971 | } else { |
|---|
| 972 | $sqlse = "SELECT $col FROM $table WHERE $where"; |
|---|
| 973 | } |
|---|
| 974 | // SQL文の実行 |
|---|
| 975 | $ret = $this->conn->getOne($sqlse, $arrval); |
|---|
| 976 | return $ret; |
|---|
| 977 | } |
|---|
| 978 | |
|---|
| 979 | function getone($sql, $arrval = array()) { |
|---|
| 980 | // SQL文の実行 |
|---|
| 981 | $ret = $this->conn->getOne($sql, $arrval); |
|---|
| 982 | return $ret; |
|---|
| 983 | |
|---|
| 984 | } |
|---|
| 985 | |
|---|
| 986 | // 一行を取得 |
|---|
| 987 | function getrow($table, $col, $where = "", $arrval = array()) { |
|---|
| 988 | if(strlen($where) <= 0) { |
|---|
| 989 | $sqlse = "SELECT $col FROM $table"; |
|---|
| 990 | } else { |
|---|
| 991 | $sqlse = "SELECT $col FROM $table WHERE $where"; |
|---|
| 992 | } |
|---|
| 993 | // SQL文の実行 |
|---|
| 994 | $ret = $this->conn->getRow($sqlse, $arrval); |
|---|
| 995 | |
|---|
| 996 | return $ret; |
|---|
| 997 | } |
|---|
| 998 | |
|---|
| 999 | // 1列取得 |
|---|
| 1000 | function getCol($table, $col, $where = "", $arrval = array()) { |
|---|
| 1001 | if (strlen($where) <= 0) { |
|---|
| 1002 | $sqlse = "SELECT $col FROM $table"; |
|---|
| 1003 | } else { |
|---|
| 1004 | $sqlse = "SELECT $col FROM $table WHERE $where"; |
|---|
| 1005 | } |
|---|
| 1006 | // SQL文の実行 |
|---|
| 1007 | return $this->conn->getCol($sqlse, $col, $arrval); |
|---|
| 1008 | } |
|---|
| 1009 | |
|---|
| 1010 | // レコードの削除 |
|---|
| 1011 | function delete($table, $where = "", $arrval = array()) { |
|---|
| 1012 | if(strlen($where) <= 0) { |
|---|
| 1013 | $sqlde = "DELETE FROM $table"; |
|---|
| 1014 | } else { |
|---|
| 1015 | $sqlde = "DELETE FROM $table WHERE $where"; |
|---|
| 1016 | } |
|---|
| 1017 | $ret = $this->conn->query($sqlde, $arrval); |
|---|
| 1018 | return $ret; |
|---|
| 1019 | } |
|---|
| 1020 | |
|---|
| 1021 | function nextval($table, $colname) { |
|---|
| 1022 | $sql = ""; |
|---|
| 1023 | // postgresqlとmysqlとで処理を分ける |
|---|
| 1024 | if (DB_TYPE == "pgsql") { |
|---|
| 1025 | $seqtable = $table . "_" . $colname . "_seq"; |
|---|
| 1026 | $sql = "SELECT NEXTVAL('$seqtable')"; |
|---|
| 1027 | }else if (DB_TYPE == "mysql") { |
|---|
| 1028 | $sql = "SELECT last_insert_id();"; |
|---|
| 1029 | } |
|---|
| 1030 | $ret = $this->conn->getOne($sql); |
|---|
| 1031 | |
|---|
| 1032 | return $ret; |
|---|
| 1033 | } |
|---|
| 1034 | |
|---|
| 1035 | function currval($table, $colname) { |
|---|
| 1036 | $sql = ""; |
|---|
| 1037 | if (DB_TYPE == "pgsql") { |
|---|
| 1038 | $seqtable = $table . "_" . $colname . "_seq"; |
|---|
| 1039 | $sql = "SELECT CURRVAL('$seqtable')"; |
|---|
| 1040 | }else if (DB_TYPE == "mysql") { |
|---|
| 1041 | $sql = "SELECT last_insert_id();"; |
|---|
| 1042 | } |
|---|
| 1043 | $ret = $this->conn->getOne($sql); |
|---|
| 1044 | |
|---|
| 1045 | return $ret; |
|---|
| 1046 | } |
|---|
| 1047 | |
|---|
| 1048 | function setval($table, $colname, $data) { |
|---|
| 1049 | $sql = ""; |
|---|
| 1050 | if (DB_TYPE == "pgsql") { |
|---|
| 1051 | $seqtable = $table . "_" . $colname . "_seq"; |
|---|
| 1052 | $sql = "SELECT SETVAL('$seqtable', $data)"; |
|---|
| 1053 | $ret = $this->conn->getOne($sql); |
|---|
| 1054 | }else if (DB_TYPE == "mysql") { |
|---|
| 1055 | $sql = "ALTER TABLE $table AUTO_INCREMENT=$data"; |
|---|
| 1056 | $ret = $this->conn->query($sql); |
|---|
| 1057 | } |
|---|
| 1058 | |
|---|
| 1059 | return $ret; |
|---|
| 1060 | } |
|---|
| 1061 | |
|---|
| 1062 | function query($n ,$arr = "", $ignore_err = false){ |
|---|
| 1063 | $result = $this->conn->query($n, $arr, $ignore_err); |
|---|
| 1064 | return $result; |
|---|
| 1065 | } |
|---|
| 1066 | |
|---|
| 1067 | // auto_incrementを取得する |
|---|
| 1068 | function get_auto_increment($table_name){ |
|---|
| 1069 | // ロックする |
|---|
| 1070 | $this->query("LOCK TABLES $table_name WRITE"); |
|---|
| 1071 | |
|---|
| 1072 | // 次のIncrementを取得 |
|---|
| 1073 | $arrRet = $this->getAll("SHOW TABLE STATUS LIKE ?", array($table_name)); |
|---|
| 1074 | $auto_inc_no = $arrRet[0]["Auto_increment"]; |
|---|
| 1075 | |
|---|
| 1076 | // 値をカウントアップしておく |
|---|
| 1077 | $this->conn->query("ALTER TABLE $table_name AUTO_INCREMENT=?" , $auto_inc_no + 1); |
|---|
| 1078 | |
|---|
| 1079 | // 解除する |
|---|
| 1080 | $this->query('UNLOCK TABLES'); |
|---|
| 1081 | |
|---|
| 1082 | return $auto_inc_no; |
|---|
| 1083 | } |
|---|
| 1084 | } |
|---|
| 1085 | |
|---|
| 1086 | |
|---|
| 1087 | $objDbConn = ""; |
|---|
| 1088 | |
|---|
| 1089 | /** |
|---|
| 1090 | * コネクションを取得する. |
|---|
| 1091 | * |
|---|
| 1092 | * (EC-CUBE からの移植) |
|---|
| 1093 | */ |
|---|
| 1094 | class SC_DbConn{ |
|---|
| 1095 | |
|---|
| 1096 | var $conn; |
|---|
| 1097 | var $dump; |
|---|
| 1098 | var $result; |
|---|
| 1099 | var $includePath; |
|---|
| 1100 | var $error_mail_to; |
|---|
| 1101 | var $error_mail_title; |
|---|
| 1102 | var $dsn; |
|---|
| 1103 | var $err_disp = true; |
|---|
| 1104 | var $dbFactory; |
|---|
| 1105 | |
|---|
| 1106 | |
|---|
| 1107 | // コンストラクタ |
|---|
| 1108 | function SC_DbConn($dsn = "", $err_disp = true, $new = false){ |
|---|
| 1109 | |
|---|
| 1110 | // Debugモード指定 |
|---|
| 1111 | $options['debug'] = true; |
|---|
| 1112 | // 既に接続されていないか、新規接続要望の場合は接続する。 |
|---|
| 1113 | if(!isset($objDbConn->connection) || $new) { |
|---|
| 1114 | if($dsn != "") { |
|---|
| 1115 | $objDbConn = DB::connect($dsn, $options); |
|---|
| 1116 | $this->dsn = $dsn; |
|---|
| 1117 | } else { |
|---|
| 1118 | if(defined('DEFAULT_DSN')) { |
|---|
| 1119 | $objDbConn = DB::connect(DEFAULT_DSN, $options); |
|---|
| 1120 | $this->dsn = DEFAULT_DSN; |
|---|
| 1121 | } else { |
|---|
| 1122 | return; |
|---|
| 1123 | } |
|---|
| 1124 | } |
|---|
| 1125 | } |
|---|
| 1126 | |
|---|
| 1127 | $this->conn = $objDbConn; |
|---|
| 1128 | $this->error_mail_to = DB_ERROR_MAIL_TO; |
|---|
| 1129 | $this->error_mail_title = DB_ERROR_MAIL_SUBJECT; |
|---|
| 1130 | $this->err_disp = $err_disp; |
|---|
| 1131 | } |
|---|
| 1132 | |
|---|
| 1133 | // クエリの実行 |
|---|
| 1134 | function query($n ,$arr = "", $ignore_err = false){ |
|---|
| 1135 | |
|---|
| 1136 | if ( $arr ) { |
|---|
| 1137 | $result = $this->conn->query($n, $arr); |
|---|
| 1138 | } else { |
|---|
| 1139 | $result = $this->conn->query($n); |
|---|
| 1140 | } |
|---|
| 1141 | |
|---|
| 1142 | if ($this->conn->isError($result) && !$ignore_err){ |
|---|
| 1143 | $this->send_err_mail ($result, $n); |
|---|
| 1144 | } |
|---|
| 1145 | |
|---|
| 1146 | $this->result = $result; |
|---|
| 1147 | return $this->result; |
|---|
| 1148 | } |
|---|
| 1149 | |
|---|
| 1150 | // 一件のみ取得 |
|---|
| 1151 | function getOne($n, $arr = ""){ |
|---|
| 1152 | |
|---|
| 1153 | if ( $arr ) { |
|---|
| 1154 | $result = $this->conn->getOne($n, $arr); |
|---|
| 1155 | } else { |
|---|
| 1156 | $result = $this->conn->getOne($n); |
|---|
| 1157 | } |
|---|
| 1158 | if ($this->conn->isError($result)){ |
|---|
| 1159 | $this->send_err_mail ($result ,$n); |
|---|
| 1160 | } |
|---|
| 1161 | $this->result = $result; |
|---|
| 1162 | |
|---|
| 1163 | return $this->result; |
|---|
| 1164 | } |
|---|
| 1165 | |
|---|
| 1166 | function getRow($n, $arr = ""){ |
|---|
| 1167 | |
|---|
| 1168 | if ( $arr ) { |
|---|
| 1169 | $result = $this->conn->getRow($n, $arr); |
|---|
| 1170 | } else { |
|---|
| 1171 | $result = $this->conn->getRow($n); |
|---|
| 1172 | } |
|---|
| 1173 | if ($this->conn->isError($result)){ |
|---|
| 1174 | $this->send_err_mail ($result ,$n); |
|---|
| 1175 | } |
|---|
| 1176 | $this->result = $result; |
|---|
| 1177 | return $this->result; |
|---|
| 1178 | } |
|---|
| 1179 | |
|---|
| 1180 | function getCol($n, $col, $arr = "") { |
|---|
| 1181 | |
|---|
| 1182 | if ($arr) { |
|---|
| 1183 | $result = $this->conn->getCol($n, $col, $arr); |
|---|
| 1184 | } else { |
|---|
| 1185 | $result = $this->conn->getCol($n, $col); |
|---|
| 1186 | } |
|---|
| 1187 | if ($this->conn->isError($result)) { |
|---|
| 1188 | $this->send_err_mail($result, $n); |
|---|
| 1189 | } |
|---|
| 1190 | $this->result = $result; |
|---|
| 1191 | return $this->result; |
|---|
| 1192 | } |
|---|
| 1193 | |
|---|
| 1194 | // SELECT文の実行結果を全て取得 |
|---|
| 1195 | function getAll($n, $arr = ""){ |
|---|
| 1196 | |
|---|
| 1197 | |
|---|
| 1198 | if(PEAR::isError($this->conn)) { |
|---|
| 1199 | if(ADMIN_MODE){ |
|---|
| 1200 | SC_Utils_Ex::sfErrorHeader("DBへの接続に失敗しました。:" . $this->dsn); |
|---|
| 1201 | }else{ |
|---|
| 1202 | SC_Utils_Ex::sfErrorHeader("DBへの接続に失敗しました。:"); |
|---|
| 1203 | } |
|---|
| 1204 | return 0; |
|---|
| 1205 | } |
|---|
| 1206 | |
|---|
| 1207 | if ( $arr ){ |
|---|
| 1208 | $result = $this->conn->getAll($n, $arr, DB_FETCHMODE_ASSOC); |
|---|
| 1209 | } else { |
|---|
| 1210 | $result = $this->conn->getAll($n, DB_FETCHMODE_ASSOC); |
|---|
| 1211 | } |
|---|
| 1212 | |
|---|
| 1213 | if ($this->conn->isError($result)){ |
|---|
| 1214 | $this->send_err_mail ($result, $n); |
|---|
| 1215 | } |
|---|
| 1216 | $this->result = $result; |
|---|
| 1217 | |
|---|
| 1218 | return $this->result; |
|---|
| 1219 | } |
|---|
| 1220 | |
|---|
| 1221 | function autoExecute($table_name, $fields_values, $sql_where = null){ |
|---|
| 1222 | |
|---|
| 1223 | if ( $sql_where ) { |
|---|
| 1224 | $result = $this->conn->autoExecute( $table_name, $fields_values, DB_AUTOQUERY_UPDATE, $sql_where); |
|---|
| 1225 | } else { |
|---|
| 1226 | $result = $this->conn->autoExecute( $table_name, $fields_values, DB_AUTOQUERY_INSERT); |
|---|
| 1227 | } |
|---|
| 1228 | |
|---|
| 1229 | if ($this->conn->isError($result)){ |
|---|
| 1230 | $this->send_err_mail ($result, $n); |
|---|
| 1231 | } |
|---|
| 1232 | $this->result = $result; |
|---|
| 1233 | return $this->result; |
|---|
| 1234 | } |
|---|
| 1235 | |
|---|
| 1236 | |
|---|
| 1237 | function prepare($n){ |
|---|
| 1238 | global $sql; |
|---|
| 1239 | $sql = $n; |
|---|
| 1240 | $result = $this->conn->prepare($n); |
|---|
| 1241 | $this->result = $result; |
|---|
| 1242 | return $this->result; |
|---|
| 1243 | } |
|---|
| 1244 | |
|---|
| 1245 | function execute($n, $obj){ |
|---|
| 1246 | global $sql; |
|---|
| 1247 | $sql = $n; |
|---|
| 1248 | $result = $this->conn->execute($n, $obj); |
|---|
| 1249 | $this->result = $result; |
|---|
| 1250 | return $this->result; |
|---|
| 1251 | } |
|---|
| 1252 | |
|---|
| 1253 | function reset(){ |
|---|
| 1254 | $this->conn->disconnect(); |
|---|
| 1255 | } |
|---|
| 1256 | |
|---|
| 1257 | function send_err_mail($result, $sql){ |
|---|
| 1258 | $url = $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; |
|---|
| 1259 | |
|---|
| 1260 | $errmsg = $url."\n\n"; |
|---|
| 1261 | $errmsg.= "SERVER_ADDR:" . $_SERVER['SERVER_ADDR'] . "\n"; |
|---|
| 1262 | $errmsg.= "REMOTE_ADDR:" . $_SERVER['REMOTE_ADDR'] . "\n"; |
|---|
| 1263 | $errmsg.= "USER_AGENT:" . $_SERVER['HTTP_USER_AGENT'] . "\n\n"; |
|---|
| 1264 | $errmsg.= $sql . "\n"; |
|---|
| 1265 | $errmsg.= $result->message . "\n\n"; |
|---|
| 1266 | $errmsg.= $result->userinfo . "\n\n"; |
|---|
| 1267 | |
|---|
| 1268 | $arrRbacktrace = array_reverse($result->backtrace); |
|---|
| 1269 | |
|---|
| 1270 | foreach($arrRbacktrace as $backtrace) { |
|---|
| 1271 | if($backtrace['class'] != "") { |
|---|
| 1272 | $func = $backtrace['class'] . "->" . $backtrace['function']; |
|---|
| 1273 | } else { |
|---|
| 1274 | $func = $backtrace['function']; |
|---|
| 1275 | } |
|---|
| 1276 | |
|---|
| 1277 | $errmsg.= $backtrace['file'] . " " . $backtrace['line'] . ":" . $func . "\n"; |
|---|
| 1278 | } |
|---|
| 1279 | |
|---|
| 1280 | print('<pre>'); |
|---|
| 1281 | //print_r(htmlspecialchars($errmsg, ENT_QUOTES)); |
|---|
| 1282 | print_r($errmsg); |
|---|
| 1283 | print('</pre>'); |
|---|
| 1284 | exit(); |
|---|
| 1285 | } |
|---|
| 1286 | |
|---|
| 1287 | } |
|---|
| 1288 | |
|---|
| 1289 | ?> |
|---|