-
Notifications
You must be signed in to change notification settings - Fork 167
/
interpreter.php
33 lines (30 loc) · 1.35 KB
/
interpreter.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
<?php
/* Run an sql script from the given file. Code taken adapted from elgg 1.7 */
function run_sql_script($scriptlocation) {
if ($script = file_get_contents($scriptlocation)) {
// global $CONFIG;
$errors = array();
$script = preg_replace('/\-\-.*\n/', '', $script);
$sql_statements = preg_split('/;[\n\r]+/', $script);
foreach($sql_statements as $statement) {
$statement = trim($statement);
// $statement = str_replace("prefix_",$CONFIG->dbprefix,$statement);
if (!empty($statement)) {
try {
$result = do_query($statement);
} catch (Exception $e) {
$errors[] = $e->getMessage();
}
}
}
if (!empty($errors)) {
$errortxt = "";
foreach($errors as $error)
$errortxt .= " {$error};";
throw new Exception('error running script: ' . $scriptlocation . ":" . $errortxt);
}
} else {
throw new Exception('ScriptNotFound:'.$scriptlocation);
}
}
?>