-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathload_rooms.php
More file actions
34 lines (30 loc) · 778 Bytes
/
Copy pathload_rooms.php
File metadata and controls
34 lines (30 loc) · 778 Bytes
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
<?php
/**
* @file
* Load the rooms table from a text file (runs from command line).
*/
// This has been run. No accidents.
exit();
include("functions.php");
function loader($file) {
$h = fopen($file, "r");
if ($h) {
$pdo = connect();
$pdo->query("TRUNCATE TABLE room");
$sth = $pdo->prepare("INSERT INTO room (rid, rate, roomsize, sleeps) VALUES (:rid, :rate, :roomsize, :sleeps)");
while ($ln = fgets($h)) {
$ln = trim($ln);
if (strpos($ln, '#') !== 0) {
$parts = preg_split('/:/', $ln);
$sth->execute(array(
':rid' => $parts[0],
':rate' => $parts[1],
':roomsize' => $parts[2],
':sleeps' => $parts[3],
));
}
}
fclose($h);
}
}
loader("rooms.txt");