-
Notifications
You must be signed in to change notification settings - Fork 3
/
sql_import.php
69 lines (45 loc) · 1.73 KB
/
sql_import.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
require_once ('config.php');
$servername = $mysql_host;
$username = $mysql_user;
$password = $mysql_password;
$dbname = $mysql_db;
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
date_default_timezone_set('Europe/Amsterdam');
$directory = $ps3_folder;
$scanned_directory = array_diff(scandir($directory), array('..', '.'));
$x = 0;
foreach ($scanned_directory as $value) {
// Renaming Files;
$newfile = str_replace(" ", '_', $value);
$newfile = str_replace("'", '', $newfile);
$newfile = str_replace("&", '', $newfile);
rename($directory."/".$value, $directory."/".$newfile);
if (strpos($value, 'iso') AND strpos($newfile, 'CONVERSION') === false) {
$game_name = str_replace(".iso", "", $newfile);
$sql = "SELECT * FROM `games` WHERE `name` = '".$game_name."';";
echo $sql."\n";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
echo "Record ".$game_name." already exists"."\n\n";
} else {
$sql = "INSERT INTO `games`(`name`, `isoname`, `covername`,`dateadded`) VALUES ('".$game_name."','".$directory."/".$newfile."','".$directory."/".$newfile.".jpg',CURRENT_TIMESTAMP);";
echo $sql."\n";
if ($conn->query($sql) === TRUE) {
echo $game_name." record created successfully \n\n";
}
else {
echo "Error: " . $sql . " " . $conn->error."\n\n";
}
}
}
}
$conn->close();
// ADDING DETAILS TO game_details
require_once('metacritic.php');
?>