NameBasics.class.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. * Class NameBasics
  17. * Import the data from imdb dataset name.basics.tsv
  18. */
  19. class NameBasics extends TSVImport {
  20. /**
  21. * @inheritDoc
  22. */
  23. public function setup() {
  24. $this->_db_table_name = 'name_basics';
  25. $this->_db_table_crate_str = "CREATE TABLE `".$this->_db_table_name."` (
  26. `nconst` varchar(16) COLLATE utf8mb4_bin NOT NULL,
  27. `primaryName` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL,
  28. `birthYear` year NOT NULL,
  29. `deathYear` year NOT NULL,
  30. `primaryProfession` text CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL,
  31. `knownForTitles` text CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL,
  32. UNIQUE KEY `nconst` (`nconst`)
  33. ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin";
  34. if($this->_createFulltext) {
  35. $this->_db_table_after_import_query[] = "ALTER TABLE `" . $this->_db_table_name . "` ADD FULLTEXT (`primaryName`)";
  36. $this->_db_table_after_import_query[] = "OPTIMIZE TABLE `" . $this->_db_table_name . "`";
  37. }
  38. }
  39. /**
  40. * @inheritDoc
  41. */
  42. public function queryValuePart($data) {
  43. $ret = '';
  44. if(!empty($data)) {
  45. if(!isset($data[5])) {
  46. return $ret;
  47. }
  48. $ret .= "(
  49. '".$this->_DB->real_escape_string($data[0])."',
  50. '".$this->_DB->real_escape_string($data[1])."',
  51. '".$this->_DB->real_escape_string($data[2])."',
  52. '".$this->_DB->real_escape_string($data[3])."',
  53. '".$this->_DB->real_escape_string($data[4])."',
  54. '".$this->_DB->real_escape_string($data[5])."'
  55. )";
  56. }
  57. return $ret;
  58. }
  59. }