Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $skus_to_add = (int)$argv[1];
- $pdo = new PDO('pgsql:host=localhost;dbname=skutest;user=postgres;password=XXXXXX');
- $pdo->exec('truncate sku');
- $insert_stmt = $pdo->prepare('insert into sku ("id", "item_id", "unit_weight", "description", "qty_available", "qty_on_order", "est_arrival", "price", "sale_price", "size_id", "size_description", "color_id", "color_description", "display_order", "created_at", "is_clearance", "color_position", "size_position", "on_promo", "debut_date", "is_sale", "display_group", "ormd", "backorderable", "barcode") values (:id, :item_id, :unit_weight, :description, :qty_available, :qty_on_order, :est_arrival, :price, :sale_price, :size_id, :size_description, :color_id, :color_description, :display_order, :created_at, :is_clearance, :color_position, :size_position, :on_promo, :debut_date, :is_sale, :display_group, :ormd, :backorderable, :barcode)');
- $start_time = microtime(true);
- for ($i=1; $i<=$skus_to_add; $i++) {
- $insert_stmt->bindValue('id', $i, PDO::PARAM_INT);
- $insert_stmt->bindValue('item_id', mt_rand(1, 1000000), PDO::PARAM_STR);
- $insert_stmt->bindValue('unit_weight', mt_rand(1, 1000), PDO::PARAM_STR);
- $insert_stmt->bindValue('description', uniqid(), PDO::PARAM_STR);
- $insert_stmt->bindValue('qty_available', mt_rand(1, 1000), PDO::PARAM_INT);
- $insert_stmt->bindValue('qty_on_order', mt_rand(1, 1000), PDO::PARAM_INT);
- $insert_stmt->bindValue('est_arrival', '2011-09-09 11:45:45', PDO::PARAM_STR);
- $insert_stmt->bindValue('price', mt_rand(1, 1000), PDO::PARAM_INT);
- $insert_stmt->bindValue('sale_price', 0.00, PDO::PARAM_INT);
- $insert_stmt->bindValue('size_id', 'xl', PDO::PARAM_STR);
- $insert_stmt->bindValue('size_description', 'Extra Large', PDO::PARAM_STR);
- $insert_stmt->bindValue('color_id', 'blue', PDO::PARAM_STR);
- $insert_stmt->bindValue('color_description', 'Blue Cloth', PDO::PARAM_STR);
- $insert_stmt->bindValue('display_order', mt_rand(1, 127), PDO::PARAM_INT);
- $insert_stmt->bindValue('created_at', '2011-09-14 14:56:12', PDO::PARAM_STR);
- $insert_stmt->bindValue('is_clearance', false, PDO::PARAM_BOOL);
- $insert_stmt->bindValue('color_position', mt_rand(1, 1000), PDO::PARAM_INT);
- $insert_stmt->bindValue('size_position', mt_rand(1, 1000), PDO::PARAM_INT);
- $insert_stmt->bindValue('on_promo', true, PDO::PARAM_BOOL);
- $insert_stmt->bindValue('debut_date', '2011-09-14 14:56:12', PDO::PARAM_STR);
- $insert_stmt->bindValue('is_sale', false, PDO::PARAM_BOOL);
- $insert_stmt->bindValue('display_group', 'ab', PDO::PARAM_STR);
- $insert_stmt->bindValue('ormd', 'na', PDO::PARAM_INT);
- $insert_stmt->bindValue('backorderable', false, PDO::PARAM_BOOL);
- $insert_stmt->bindValue('barcode', uniqid(), PDO::PARAM_STR);
- $insert_stmt->execute();
- }
- $end_time = microtime(true);
- $script_run_time = ($end_time-$start_time);
- $peak_memory = (memory_get_peak_usage()/(1024*1024));
- $peak_memory = round($peak_memory, 4);
- echo("Added {$skus_to_add} SKUs.".PHP_EOL);
- echo("This script took {$script_run_time} seconds to import {$skus_to_add} SKUs.".PHP_EOL);
- echo("This script used {$peak_memory}MB.".PHP_EOL);
- echo(PHP_EOL);
- unset($server);
- exit(0);
Add Comment
Please, Sign In to add comment