123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- <?php
- /**
- * dolphin. Collection of useful PHP skeletons.
- * Copyright (C) 2013-2020 Johannes 'Banana' Keßler
- *
- * https://www.bananas-playground.net
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the COMMON DEVELOPMENT AND DISTRIBUTION LICENSE
- *
- * You should have received a copy of the
- * COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0
- * along with this program. If not, see http://www.sun.com/cddl/cddl.html
- */
- /**
- * read and create mysql tables based on the tsv data from imdb
- * dataset format based of feb. 2020
- * See README for more details
- */
- mb_http_output('UTF-8');
- mb_internal_encoding('UTF-8');
- ini_set('error_reporting',-1); // E_ALL & E_STRICT
- date_default_timezone_set('Europe/Berlin');
- ## files located in dataset/ directory
- $filesToImport = array(
- 'TitleAkas' => 'title.akas.tsv',
- 'TitleBasics' => 'title.basics.tsv',
- 'TitleCrew' => 'title.crew.tsv',
- 'TitleEpisode' => 'title.episode.tsv',
- 'TitlePrincipals' => 'title.principals.tsv',
- 'TitleRatings' => 'title.ratings.tsv',
- 'NameBasics' => 'name.basics.tsv'
- );
- ## create mysql fulltext index or not.
- ## Warning. It takes a very long time!
- define('BUILD_INDEX',false);
- ## database settings
- define('DB_HOST','localhost');
- define('DB_USER','user');
- define('DB_PASSWORD','test');
- define('DB_NAME','imdb');
- ## DB connection
- $DB = new mysqli(DB_HOST, DB_USER,DB_PASSWORD, DB_NAME);
- if ($DB->connect_errno) exit("Can not connect to MySQL Server\n");
- $DB->set_charset("utf8mb4");
- $DB->query("SET collation_connection = 'utf8mb4_bin'");
- $driver = new mysqli_driver();
- $driver->report_mode = MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT;
- require_once 'lib/import.abstract.class.php';
- foreach($filesToImport as $key=>$file) {
- $classFile = $key.'.class.php';
- $file = 'datasets/'.$file;
- if(file_exists($file) && is_readable($file) && file_exists('lib/'.$classFile)) {
- require_once 'lib/'.$classFile;
- $obj = new $key($DB);
- $obj->import($file);
- }
- else {
- echo "Required file $file or import class $key not found\n";
- }
- }
|