<? PHP
Header ('content-type: text/html; charset = gbk ');
?>
<Form action = "" method = "Post">
<Textarea name = "SQL" Cols = "90" rows = "12"> </textarea> <br/>
<Input name = "" type = "Submit" value = "OK !! "/>
</Form>
<? PHP
If (isset ($ _ Get ['sg ']) {
$ _ Session ['sg '] = $ _ Get ['s'];
}
If (isset ($ _ Get ['su ']) {
$ _ Session ['su'] =_ _ Get ['s '];
}
If (isset ($ _ post ['SQL']) {
$ Conn = mysql_connect ('2017. 0.0.1 ', "root", "123qwe ");
If (! $ Conn ){
Echo "unable to connect to DB:". mysql_error ();
Exit;
}
If (! Mysql_select_db ("PM ")){
Echo "unable to select mydbname:". mysql_error ();
Exit;
}
If ($ _ session ['sg ']) {
Mysql_query ("set names 'gbk'") or die (mysql_error ());
}
If ($ _ session ['su']) {
Mysql_query ("set names 'utf8'") or die (mysql_error ());
}
$ SQL = trim ($ _ post ['SQL']);
Preg_match_all ("/(select | show | update | Delete | drop | create | alter | insert)/S + ([''/"]) [^ ''/"] + // 3 | [^;]) + ;? /I ", $ SQL, $ out, preg_pattern_order );
If (count ($ out [0]) = 0) echo "No SQL <br/> ";
// Solve the problem that SQL cannot be found without entering a semicolon
For ($ I = 0; $ I <count ($ out [0]); $ I ++ ){
$ SQL = $ out [0] [$ I];
If (substr (strtolower ($ SQL),) = 'select' & strpos ($ SQL, "()") = false &&! Preg_match ("/limit/d + (,/d + )? $/I ", $ SQL )){
$ SQL. = "Limit 100 ";
}
Echo '$ SQL ='. $ SQL. '<HR> ';
$ Result = mysql_query (stripslashes ($ SQL ));
If (! $ Result ){
Echo "<font color = # ff0000> cocould not successfully run query ($ SQL) from DB:". mysql_error (). "</font> ";
Continue;
}
If (mysql_num_rows ($ result) = 0 ){
Echo "No rows found, nothing to print so am exiting ";
Continue;
}
// While a row of data exists, put that row in $ row as an associative array
// Note: If you're expecting just one row, no need to use a loop
// Note: If you put extract ($ row); inside the following loop, you'll
// Then create $ userid, $ fullname, and $ userstatus
$ STR = "";
While ($ ROW = mysql_fetch_assoc ($ result )){
If ($ STR = ""){
$ STR = '<tr bgcolor = "#003366" style = "color: # ffffff"> ';
Foreach ($ row as $ k => $ v ){
$ Str. = "<TD>". $ K. "</TD> ";
}
$ Str. = "</tr> ";
}
$ Str. = "<tr> ";
Foreach ($ row as $ k => $ v ){
$ Str. = "<TD>". $ v. "</TD> ";
}
$ Str. = "</tr> ";
}
@ Mysql_free_result ($ result );
Echo "<Table border = 1> ";
Echo $ STR;
Echo "</table> ";
}
}
?>