-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathajax-execute-query.php
More file actions
48 lines (40 loc) · 1.63 KB
/
Copy pathajax-execute-query.php
File metadata and controls
48 lines (40 loc) · 1.63 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
<?php
error_reporting(0);
require_once "lib.php";
if (isset($_POST['target_db']) && isset($_POST['sql'])) {
header("Content-Type: application/json");
$langCode = get_lang_code();
$lang = new Language($langCode);
$target = $_POST['target_db']; // 'db1' atau 'db2'
$suffix = ($target === 'db1') ? '1' : '2';
$driver = get_post('driver' . $suffix, 'mysql');
$host = get_post('host' . $suffix, 'localhost');
$port = get_post('port' . $suffix, 3306);
$db = get_post('db' . $suffix);
$user = get_post('user' . $suffix, 'root');
$pass = get_post('pass' . $suffix, '');
// Ambil SQL mentah (jangan gunakan get_post karena akan menghapus quote)
$sql = isset($_POST['sql']) ? $_POST['sql'] : '';
if (empty($sql) || strpos(trim($sql), '--') === 0) {
echo json_encode(array('success' => false, 'error' => $lang->get('no_valid_sql')));
exit;
}
try {
$pdo = get_db_connection($driver, $host, $port, $db, $user, $pass);
// Pisahkan statement berdasarkan titik koma untuk menangani multiple queries
$statements = explode(";", $sql);
foreach ($statements as $stmt) {
$stmt = trim($stmt);
if (!empty($stmt)) {
// Lewati komentar
if (strpos($stmt, '--') === 0) continue;
$pdo->exec($stmt);
}
}
echo json_encode(array('success' => true));
} catch (PDOException $e) {
echo json_encode(array('success' => false, 'error' => $e->getMessage()));
} catch (Exception $e) {
echo json_encode(array('success' => false, 'error' => $e->getMessage()));
}
}