forked from GEWIS/gewisweb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimportdb.php
46 lines (38 loc) · 1.1 KB
/
importdb.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
<?php
/**
* This is a separate script that copies the GEWIS Report Database to the Web
* database.
*
* It is a simple PostgreSQL to MySQL copy script.
*/
// connections
$pgconn = new PDO('pgsql:host=localhost;dbname=gewis_report;user=;password=');
$myconn = new PDO('mysql:host=localhost;dbname=gewisweb_dev', '', '');
/* which tables to sync */
$tables = array(
'Address',
'Boardmember',
'Decision',
'Mailinglist',
'Meeting',
'Member',
'members_mailinglists',
'Organ',
'OrganMember',
'SubDecision'
);
foreach ($tables as $table) {
$query = "SELECT * FROM $table";
$stmt = $pgconn->query($query);
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
$fields = '(' . implode(', ', array_keys($row)) . ')';
$values = '(' . implode(', ', array_map(function ($a) {
return ':' . $a;
}, array_keys($row))) . ')';
$truncate = "TRUNCATE TABLE $table";
$myconn->query($truncate);
$sql = "INSERT INTO $table $fields VALUES $values";
$stmtt = $myconn->prepare($sql);
$stmtt->execute($row);
}
}