-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.php
More file actions
125 lines (108 loc) · 4.38 KB
/
install.php
File metadata and controls
125 lines (108 loc) · 4.38 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<?php
/**
* install.php
*
* Created by PhpStorm.
* User: pamela
* Date: 7/10/17
* Time: 1:47 PM
*/
// INCLUDES ------------------------------------------------------------------------------------
// Tests to make sure code is not doing evil
require_once('tests.php');
// Library for connecting to Twitter API
require_once('TwitterAPIExchange.php');
// Make needed connetions to DB
require_once('config.php');
// Create database as needed
$query = "CREATE DATABASE IF NOT EXISTS $dbname";
$result = mysqli_query($conn, $query);
if ($result==FALSE) {
die("Error: ".mysqli_error($conn)."\n");
}
mysqli_select_db($conn,"$dbname");
// Add each table as needed
// ------------------------
$query = "DROP TABLE tweeps; DROP TABLE connections;";
$result = mysqli_query($conn, $query);
// == TWEEPS =======
$table = "tweeps";
$query = "CREATE TABLE `tweeps` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`tweep_id` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
`tweep_username` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
`tweep_name` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
`description` blob,
`followers` int(11) DEFAULT '0',
`friends` int(11) DEFAULT '0',
`tweets` int(11) DEFAULT '0',
`verified` int(11) DEFAULT '0',
`done` int(11) DEFAULT '0',
`count` int(11) DEFAULT '0',
`created_at` varchar(100) COLLATE utf8_unicode_ci DEFAULT '0',
`update_at` varchar(100) COLLATE utf8_unicode_ci DEFAULT '0',
PRIMARY KEY (`id`),
UNIQUE KEY `tweep_id` (`tweep_id`)
) ENGINE=InnoDB AUTO_INCREMENT=1587 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;";
make_table ($conn, $dbname, $table, $query);
// == connections =======
$table = "connections";
$query = "CREATE TABLE `connections` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`tweep_id` varchar(48) COLLATE utf8_unicode_ci DEFAULT NULL,
`friend_id` varchar(48) COLLATE utf8_unicode_ci DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `friend_id` (`friend_id`)
) ENGINE=InnoDB AUTO_INCREMENT=11295888 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;";
make_table ($conn, $dbname, $table, $query);
// == network ===========
$table = "network";
$query = "CREATE TABLE `network` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`tweep_id` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
`tweep_username` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
`tweep_name` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
`description` blob,
`verified` int(11) DEFAULT '0',
`followers` int(11) DEFAULT '0',
`friends` int(11) DEFAULT '0',
`tweets` int(11) DEFAULT '0',
`done` int(11) DEFAULT '0',
`count` int(11) DEFAULT '0',
`created_at` varchar(100) COLLATE utf8_unicode_ci DEFAULT '0',
`update_at` varchar(100) COLLATE utf8_unicode_ci DEFAULT '0',
PRIMARY KEY (`id`),
UNIQUE KEY `tweep_id` (`tweep_id`)
) ENGINE=InnoDB AUTO_INCREMENT=819541 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;";
make_table ($conn, $dbname, $table, $query);
// == combos ============
$table = "combos";
$query = "CREATE TABLE `combos` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`HubA_id` varchar(48) DEFAULT NULL,
`HubA_name` varchar(48) DEFAULT NULL,
`HubB_id` varchar(48) DEFAULT NULL,
`HubB_name` varchar(48) DEFAULT NULL,
`Count` int(11) DEFAULT '0',
PRIMARY KEY (`id`),
KEY `HubA` (`HubA_id`),
KEY `HubB` (`HubA_name`)
) ENGINE=InnoDB AUTO_INCREMENT=351431 DEFAULT CHARSET=latin1;";
make_table ($conn, $dbname, $table, $query);
// ---------------------------
// FUNCTION: Create Table
// ---------------------------
function make_table($conn, $dbname, $table, $query) {
$check_table = "SELECT table_name FROM information_schema.tables
WHERE table_schema = '$dbname' AND table_name = '$table'";
$result = mysqli_query($conn, $check_table);
if (mysqli_num_rows($result) == 0) {
$result = mysqli_query($conn, $query);
if ($result==FALSE) {
die("Error: ".mysqli_error($conn)."\n");
} else {
echo "$table table created.\n";
}
} else echo "$table table exists.\n";
}
?>