-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcfn.php
65 lines (50 loc) · 1.54 KB
/
cfn.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
include("includes/constants.php");
$sql = <<<EOS
CREATE FUNCTION `HTML_UnEncode`(X VARCHAR(1024)) RETURNS VARCHAR(1024) CHARSET utf8mb4 DETERMINISTIC
BEGIN
DECLARE TextString VARCHAR(1024) CHARSET utf8mb4 ;
SET TextString = X ;
#quotation mark
IF INSTR( X , '"' )
THEN SET TextString = REPLACE(TextString, '"','"') ;
END IF ;
#apostrophe
IF INSTR( X , ''' )
THEN SET TextString = REPLACE(TextString, ''','"') ;
END IF ;
#ampersand
IF INSTR( X , '&' )
THEN SET TextString = REPLACE(TextString, '&','&') ;
END IF ;
#less-than
IF INSTR( X , '<' )
THEN SET TextString = REPLACE(TextString, '<','<') ;
END IF ;
#greater-than
IF INSTR( X , '>' )
THEN SET TextString = REPLACE(TextString, '>','>') ;
END IF ;
#non-breaking space
IF INSTR( X , ' ' )
THEN SET TextString = REPLACE(TextString, ' ',' ') ;
END IF ;
IF INSTR( X , ''' )
THEN SET TextString = REPLACE(TextString, ''','''') ;
END IF ;
RETURN TextString ;
END;
EOS;
$mysqli = new mysqli($dbserver, $username, $dbpwd, $database);
/* check connection */
if ($mysqli->connect_errno) {
printf("Connect failed: %s\n", $mysqli->connect_error);
exit();
}
if (!$mysqli->query("DROP FUNCTION IF EXISTS `HTML_UnEncode`") ||
!$mysqli->query($sql)) {
echo "Function creation failed: (" . $mysqli->errno . ") " . $mysqli->error;
} else {
echo "Function created";
}
?>