1
0

import.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. /**
  3. * dolphin. Collection of useful PHP skeletons.
  4. * Copyright (C) 2013-2020 Johannes 'Banana' Keßler
  5. *
  6. * https://www.bananas-playground.net
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the COMMON DEVELOPMENT AND DISTRIBUTION LICENSE
  10. *
  11. * You should have received a copy of the
  12. * COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0
  13. * along with this program. If not, see http://www.sun.com/cddl/cddl.html
  14. */
  15. /**
  16. * read and create mysql tables based on the tsv data from imdb
  17. * dataset format based of feb. 2020
  18. * See README for more details
  19. */
  20. mb_http_output('UTF-8');
  21. mb_internal_encoding('UTF-8');
  22. ini_set('error_reporting',-1); // E_ALL & E_STRICT
  23. date_default_timezone_set('Europe/Berlin');
  24. ## files located in dataset/ directory
  25. $filesToImport = array(
  26. 'TitleAkas' => 'title.akas.tsv',
  27. 'TitleBasics' => 'title.basics.tsv',
  28. 'TitleCrew' => 'title.crew.tsv',
  29. 'TitleEpisode' => 'title.episode.tsv',
  30. 'TitlePrincipals' => 'title.principals.tsv',
  31. 'TitleRatings' => 'title.ratings.tsv',
  32. 'NameBasics' => 'name.basics.tsv'
  33. );
  34. ## create mysql fulltext index or not.
  35. ## Warning. It takes a very long time!
  36. define('BUILD_INDEX',false);
  37. ## database settings
  38. define('DB_HOST','localhost');
  39. define('DB_USER','user');
  40. define('DB_PASSWORD','test');
  41. define('DB_NAME','imdb');
  42. ## DB connection
  43. $DB = new mysqli(DB_HOST, DB_USER,DB_PASSWORD, DB_NAME);
  44. if ($DB->connect_errno) exit("Can not connect to MySQL Server\n");
  45. $DB->set_charset("utf8mb4");
  46. $DB->query("SET collation_connection = 'utf8mb4_bin'");
  47. $driver = new mysqli_driver();
  48. $driver->report_mode = MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT;
  49. require_once 'lib/import.abstract.class.php';
  50. foreach($filesToImport as $key=>$file) {
  51. $classFile = $key.'.class.php';
  52. $file = 'datasets/'.$file;
  53. if(file_exists($file) && is_readable($file) && file_exists('lib/'.$classFile)) {
  54. require_once 'lib/'.$classFile;
  55. $obj = new $key($DB);
  56. $obj->import($file);
  57. }
  58. else {
  59. echo "Required file $file or import class $key not found\n";
  60. }
  61. }