PluginProbe
WP-DBManager / 2.50
WP-DBManager v2.50
4.0.0 trunk 1.00 2.00 2.01 2.02 2.03 2.04 2.05 2.10 2.11 2.20 2.30 2.31 2.40 2.50 2.65 2.70 2.71 2.72 2.73 2.74 2.75 2.76 2.78 All 40 releases
wp-dbmanager / database-run.php

database-run.php in WP-DBManager 2.50, at database-run.php

107 lines 4.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 +----------------------------------------------------------------+
4 | |
5 | WordPress 2.8 Plugin: WP-DBManager 2.50 |
6 | Copyright (c) 2009 Lester "GaMerZ" Chan |
7 | |
8 | File Written By: |
9 | - Lester "GaMerZ" Chan |
10 | - http://lesterchan.net |
11 | |
12 | File Information: |
13 | - Database Run Query |
14 | - wp-content/plugins/wp-dbmanager/database-run.php |
15 | |
16 +----------------------------------------------------------------+
17 */
18
19
20 ### Check Whether User Can Manage Database
21 if(!current_user_can('manage_database')) {
22 die('Access Denied');
23 }
24
25
26 ### Variables Variables Variables
27 $base_name = plugin_basename('wp-dbmanager/database-manager.php');
28 $base_page = 'admin.php?page='.$base_name;
29 $backup = array();
30 $backup_options = get_option('dbmanager_options');
31 $backup['date'] = current_time('timestamp');
32 $backup['mysqldumppath'] = $backup_options['mysqldumppath'];
33 $backup['mysqlpath'] = $backup_options['mysqlpath'];
34 $backup['path'] = $backup_options['path'];
35
36
37 ### Form Processing
38 if($_POST['do']) {
39 // Decide What To Do
40 switch($_POST['do']) {
41 case __('Run', 'wp-dbmanager'):
42 $sql_queries2 = trim($_POST['sql_query']);
43 $totalquerycount = 0;
44 $successquery = 0;
45 if($sql_queries2) {
46 $sql_queries = array();
47 $sql_queries2 = explode("\n", $sql_queries2);
48 foreach($sql_queries2 as $sql_query2) {
49 $sql_query2 = trim(stripslashes($sql_query2));
50 $sql_query2 = preg_replace("/[\r\n]+/", '', $sql_query2);
51 if(!empty($sql_query2)) {
52 $sql_queries[] = $sql_query2;
53 }
54 }
55 if($sql_queries) {
56 foreach($sql_queries as $sql_query) {
57 if (preg_match("/^\\s*(insert|update|replace|delete|create|alter) /i",$sql_query)) {
58 $run_query = $wpdb->query($sql_query);
59 if(!$run_query) {
60 $text .= "<span dir=\"ltr\"><font color=\"red\">$sql_query</font></span><br />";
61 } else {
62 $successquery++;
63 $text .= "<span dir=\"ltr\"><font color=\"green\">$sql_query</font></span><br />";
64 }
65 $totalquerycount++;
66 } elseif (preg_match("/^\\s*(select|drop|show|grant) /i",$sql_query)) {
67 $text .= "<span dir=\"ltr\"><font color=\"red\">$sql_query</font></span><br />";
68 $totalquerycount++;
69 }
70 }
71 $text .= '<font color="blue">'.number_format_i18n($successquery).'/'.number_format_i18n($totalquerycount).' '.__('Query(s) Executed Successfully', 'wp-dbmanager').'</font>';
72 } else {
73 $text = '<font color="red">'.__('Empty Query', 'wp-dbmanager').'</font>';
74 }
75 } else {
76 $text = '<font color="red">'.__('Empty Query', 'wp-dbmanager').'</font>';
77 }
78 break;
79 }
80 }
81 ?>
82 <?php if(!empty($text)) { echo '<!-- Last Action --><div id="message" class="updated fade"><p>'.$text.'</p></div>'; } ?>
83 <!-- Run SQL Query -->
84 <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>?page=<?php echo plugin_basename(__FILE__); ?>">
85 <div class="wrap">
86 <div id="icon-wp-dbmanager" class="icon32"><br /></div>
87 <h2><?php _e('Run SQL Query', 'wp-dbmanager'); ?></h2>
88 <br style="clear" />
89 <div>
90 <strong><?php _e('Seperate Multiple Queries With A New Line', 'wp-dbmanager'); ?></strong><br />
91 <font color="green"><?php _e('Use Only INSERT, UPDATE, REPLACE, DELETE, CREATE and ALTER statements.', 'wp-dbmanager'); ?></font>
92 </div>
93 <table class="form-table">
94 <tr>
95 <td align="center"><textarea cols="120" rows="30" name="sql_query" style="width: 99%;" dir="ltr" ></textarea></td>
96 </tr>
97 <tr>
98 <td align="center"><input type="submit" name="do" value="<?php _e('Run', 'wp-dbmanager'); ?>" class="button" />&nbsp;&nbsp;<input type="button" name="cancel" value="<?php _e('Cancel', 'wp-dbmanager'); ?>" class="button" onclick="javascript:history.go(-1)" /></td>
99 </tr>
100 </table>
101 <p>
102 <?php _e('1. CREATE statement will return an error, which is perfectly normal due to the database class. To confirm that your table has been created check the Manage Database page.', 'wp-dbmanager'); ?><br />
103 <?php _e('2. UPDATE statement may return an error sometimes due to the newly updated value being the same as the previous value.', 'wp-dbmanager'); ?><br />
104 <?php _e('3. ALTER statement will return an error because there is no value returned.', 'wp-dbmanager'); ?>
105 </p>
106 </div>
107 </form>