Guest User

Untitled

a guest
Jan 23rd, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.08 KB | None | 0 0
  1. <?php
  2.  
  3. $skus_to_add = (int)$argv[1];
  4.  
  5. $pdo = new PDO('pgsql:host=localhost;dbname=skutest;user=postgres;password=XXXXXX');
  6. $pdo->exec('truncate sku');
  7.  
  8. $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)');
  9.  
  10. $start_time = microtime(true);
  11. for ($i=1; $i<=$skus_to_add; $i++) {
  12. $insert_stmt->bindValue('id', $i, PDO::PARAM_INT);
  13. $insert_stmt->bindValue('item_id', mt_rand(1, 1000000), PDO::PARAM_STR);
  14. $insert_stmt->bindValue('unit_weight', mt_rand(1, 1000), PDO::PARAM_STR);
  15. $insert_stmt->bindValue('description', uniqid(), PDO::PARAM_STR);
  16. $insert_stmt->bindValue('qty_available', mt_rand(1, 1000), PDO::PARAM_INT);
  17. $insert_stmt->bindValue('qty_on_order', mt_rand(1, 1000), PDO::PARAM_INT);
  18. $insert_stmt->bindValue('est_arrival', '2011-09-09 11:45:45', PDO::PARAM_STR);
  19. $insert_stmt->bindValue('price', mt_rand(1, 1000), PDO::PARAM_INT);
  20. $insert_stmt->bindValue('sale_price', 0.00, PDO::PARAM_INT);
  21. $insert_stmt->bindValue('size_id', 'xl', PDO::PARAM_STR);
  22. $insert_stmt->bindValue('size_description', 'Extra Large', PDO::PARAM_STR);
  23. $insert_stmt->bindValue('color_id', 'blue', PDO::PARAM_STR);
  24. $insert_stmt->bindValue('color_description', 'Blue Cloth', PDO::PARAM_STR);
  25. $insert_stmt->bindValue('display_order', mt_rand(1, 127), PDO::PARAM_INT);
  26. $insert_stmt->bindValue('created_at', '2011-09-14 14:56:12', PDO::PARAM_STR);
  27. $insert_stmt->bindValue('is_clearance', false, PDO::PARAM_BOOL);
  28. $insert_stmt->bindValue('color_position', mt_rand(1, 1000), PDO::PARAM_INT);
  29. $insert_stmt->bindValue('size_position', mt_rand(1, 1000), PDO::PARAM_INT);
  30. $insert_stmt->bindValue('on_promo', true, PDO::PARAM_BOOL);
  31. $insert_stmt->bindValue('debut_date', '2011-09-14 14:56:12', PDO::PARAM_STR);
  32. $insert_stmt->bindValue('is_sale', false, PDO::PARAM_BOOL);
  33. $insert_stmt->bindValue('display_group', 'ab', PDO::PARAM_STR);
  34. $insert_stmt->bindValue('ormd', 'na', PDO::PARAM_INT);
  35. $insert_stmt->bindValue('backorderable', false, PDO::PARAM_BOOL);
  36. $insert_stmt->bindValue('barcode', uniqid(), PDO::PARAM_STR);
  37.  
  38. $insert_stmt->execute();
  39. }
  40. $end_time = microtime(true);
  41.  
  42. $script_run_time = ($end_time-$start_time);
  43.  
  44. $peak_memory = (memory_get_peak_usage()/(1024*1024));
  45. $peak_memory = round($peak_memory, 4);
  46.  
  47. echo("Added {$skus_to_add} SKUs.".PHP_EOL);
  48. echo("This script took {$script_run_time} seconds to import {$skus_to_add} SKUs.".PHP_EOL);
  49. echo("This script used {$peak_memory}MB.".PHP_EOL);
  50. echo(PHP_EOL);
  51.  
  52. unset($server);
  53. exit(0);
Add Comment
Please, Sign In to add comment