Guest User

Untitled

a guest
Jul 11th, 2016
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.67 KB | None | 0 0
  1.  
  2. error_reporting( error_reporting() & ~E_NOTICE );
  3. ini_set('max_execution_time', 3000);
  4. ini_set('memory_limit', '2G'); // due to memory error
  5. //connect to mysql db
  6. $con =mysqli_connect("x.x.x.x", "user", "password", "bdnaem");;
  7. //connect to the employee database
  8.  
  9.  
  10. //read the json file contents
  11. $jsondata = file_get_contents('big9.file');
  12.  
  13. //convert json object to php associative array
  14. $data = json_decode($jsondata, true);
  15. //mysqli_query("BEGIN");
  16.  
  17. $sql = "INSERT INTO `Items`(`Buy`, `Issued`, `Price`, `Duration`, `ID`, `Minvolume`, `Volume Entered`, `RangeR`, `Station`, `Type`)
  18. VALUES ";
  19.  
  20. $rowcount = 0;
  21. $trowcount = 0;
  22. $lim = 1000;
  23. echo count($data);
  24.  
  25. foreach ($data['items'] as $row){
  26.  
  27. //get the items details
  28. $Buy = $row['buy'];
  29. $Issued = $row['issued'];
  30. $Price = $row['price'];
  31. $Duration = $row['duration'];
  32. $ID = $row['id'];
  33. $Minvolume = $row['minvolume'];
  34. $Volume_Entered = $row['volumeEntered'];
  35. $RangeR = $row['range'];
  36. $Station = $row['station'];
  37. $Type = $row['type'];
  38.  
  39. //insert into mysql table
  40. $sql .= "('$Buy', '$Issued', '$Price', '$Duration', '$ID', '$Minvolume', '$Volume_Entered', '$RangeR', '$Station', '$Type')";
  41.  
  42. $rowcount++;
  43. if($rowcount == $lim) {
  44.  
  45. if(!mysqli_query($con,$sql))
  46. {
  47. die('Error : ' . mysqli_error($con));
  48. }
  49. $rowcount = 0;
  50. $trowcount ++;
  51. $sql = "INSERT INTO `Items`(`Buy`, `Issued`, `Price`, `Duration`, `ID`, `Minvolume`, `Volume Entered`, `RangeR`, `Station`, `Type`)
  52. VALUES ";
  53. } else {
  54. $sql .= ",";
  55.  
  56. }
  57.  
  58.  
  59. }
  60. if(!mysqli_query($con,$sql))
  61. {
  62. die('Error : ' . mysqli_error($con));<----Here error
  63. }
  64.  
  65.  
  66.  
  67. $time = microtime(true) - $_SERVER["REQUEST_TIME_FLOAT"];
  68.  
  69. echo "Did nothing in $time seconds\n";
  70.  
  71. ?>
Add Comment
Please, Sign In to add comment