Advertisement
Guest User

Untitled

a guest
May 8th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.65 KB | None | 0 0
  1. <FORM>
  2. <?
  3. #; Fix for when register_globals is off. Also, turns out you dont need quotes unless a string has special characters.
  4.    $OPTS=$HTTP_GET_VARS+ARRAY(SERV=>localhost,USER=>root,PASS=>pasword123,DB=>mysql);
  5.     FOREACH($OPTS as $OPTS1 => $OPTS2) $$OPTS1=$OPTS2;
  6. PHP?>
  7. <TEXTAREA NAME=SQL ROWS=8 COLS=70><?=$SQL?></TEXTAREA>
  8. <INPUT TYPE=SUBMIT>
  9. </FORM>
  10. <HR>
  11. <?PHP
  12.  
  13.     MYSQL_CONNECT($SERV, $USER, $PASS)
  14.       OR DIE("Can't connect to DBSERVer. Check $USER:$PASS@$SERV");
  15.     MYSQL_SELECT_DB($DB)
  16.       OR DIE("Can't select DB; check database $DB when logging in to $USER:$PASS@$SERV");
  17.  
  18. #; New feature: Allow multiple commands!
  19.    $SQL2=EXPLODE(";",$SQL);
  20.     FOREACH($SQL2 AS $SQL3):
  21.  
  22.     $SQL4=MYSQL_QUERY($SQL3);
  23.  
  24.     $ALL[]=$SQL4;
  25.  
  26.     ENDFOREACH;
  27.  
  28. #; New feature 2: Show results for each query!!
  29.    FOR($X=0;$X<SIZEOF($SQL2);++$X):
  30.     $SQL5=$SQL2[$X];
  31. #; New code ends here
  32.  
  33.     IF($RES[$X]):
  34.         PRINT "<TABLE>";
  35.         WHILE($SQL3=MYSQL_FETCH_ROW($SQL5)) PRINT "<TR>".IMPLODE("<TD>",$SQL3);
  36.         ECHO "</TABLE>";
  37. #; No idea why PRINT didn't work, but I once had a bug that went away when I changed this to ECHO, so leaving it alone.
  38.        ELSE:
  39.             PRINT $SQL5." did not produce a result (NOTE: Connected to dbserver as $USER:$PASS@$SERV, DB is $DB)";
  40.             ENDIF;
  41.  
  42. #; Whoops, add an ENDFOR here.
  43.    ENDFOR;
  44. PHP?>
  45. <HR>
  46. <COMMENT This is a useful trick I came up with for makeing HTML comments>
  47. <COMMENT Print the form a second time to save scrolling. Another FORM tag is needed to separate it from the first though>
  48. <FORM>
  49.  
  50. <TEXTAREA NAME=SQL ROWS=8 COLS=70><?=$SQL?></TEXTAREA>
  51. <INPUT TYPE=SUBMIT>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement