PluginProbe
WP-DBManager / 2.80.9
WP-DBManager v2.80.9
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.80.9, at database-run.php

95 lines 3.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 ### Check Whether User Can Manage Database
3 if ( ! current_user_can( 'install_plugins' ) ) {
4 die( 'Access Denied' );
5 }
6
7
8 ### Variables Variables Variables
9 $base_name = plugin_basename('wp-dbmanager/database-manager.php');
10 $base_page = 'admin.php?page='.$base_name;
11 $backup = array();
12 $backup_options = get_option('dbmanager_options');
13 $backup['date'] = current_time('timestamp');
14 $backup['mysqldumppath'] = $backup_options['mysqldumppath'];
15 $backup['mysqlpath'] = $backup_options['mysqlpath'];
16 $backup['path'] = $backup_options['path'];
17
18
19 ### Form Processing
20 if(!empty($_POST['do'])) {
21 $text = '';
22 // Decide What To Do
23 switch($_POST['do']) {
24 case __('Run', 'wp-dbmanager'):
25 check_admin_referer('wp-dbmanager_run');
26 $sql_queries2 = trim($_POST['sql_query']);
27 $totalquerycount = 0;
28 $successquery = 0;
29 if($sql_queries2) {
30 $sql_queries = array();
31 $sql_queries2 = explode("\n", $sql_queries2);
32 foreach($sql_queries2 as $sql_query2) {
33 $sql_query2 = trim(stripslashes($sql_query2));
34 $sql_query2 = preg_replace("/[\r\n]+/", '', $sql_query2);
35 if(!empty($sql_query2)) {
36 $sql_queries[] = $sql_query2;
37 }
38 }
39 if($sql_queries) {
40 foreach( $sql_queries as $sql_query ) {
41 if ( preg_match( "/LOAD_FILE/i", $sql_query ) ) {
42 $text .= "<p style=\"color: red;\">$sql_query</p>";
43 $totalquerycount++;
44 } elseif( preg_match( "/^\\s*(select|drop|show|grant) /i", $sql_query ) ) {
45 $text .= "<p style=\"color: red;\">$sql_query</p>";
46 $totalquerycount++;
47 } else if ( preg_match( "/^\\s*(insert|update|replace|delete|create|alter) /i", $sql_query ) ) {
48 $run_query = $wpdb->query( $sql_query );
49 if( ! $run_query ) {
50 $text .= "<p style=\"color: red;\">$sql_query</p>";
51 } else {
52 $successquery++;
53 $text .= "<p style=\"color: green;\">$sql_query</p>";
54 }
55 $totalquerycount++;
56 }
57 }
58 $text .= '<p style="color: blue;">'.number_format_i18n($successquery).'/'.number_format_i18n($totalquerycount).' '.__('Query(s) Executed Successfully', 'wp-dbmanager').'</p>';
59 } else {
60 $text = '<p style="color: red;">'.__('Empty Query', 'wp-dbmanager').'</p>';
61 }
62 } else {
63 $text = '<p style="color: red;">'.__('Empty Query', 'wp-dbmanager').'</p>';
64 }
65 break;
66 }
67 }
68 ?>
69 <?php if(!empty($text)) { echo '<!-- Last Action --><div id="message" class="updated fade"><p>'.$text.'</p></div>'; } ?>
70 <!-- Run SQL Query -->
71 <form method="post" action="<?php echo admin_url('admin.php?page='.plugin_basename(__FILE__)); ?>">
72 <?php wp_nonce_field('wp-dbmanager_run'); ?>
73 <div class="wrap">
74 <h2><?php _e('Run SQL Query', 'wp-dbmanager'); ?></h2>
75 <br style="clear" />
76 <div>
77 <strong><?php _e('Separate Multiple Queries With A New Line', 'wp-dbmanager'); ?></strong><br />
78 <p style="color: green;"><?php _e('Use Only INSERT, UPDATE, REPLACE, DELETE, CREATE and ALTER statements.', 'wp-dbmanager'); ?></p>
79 </div>
80 <table class="form-table">
81 <tr>
82 <td align="center"><textarea cols="120" rows="30" name="sql_query" style="width: 99%;" dir="ltr" ></textarea></td>
83 </tr>
84 <tr>
85 <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>
86 </tr>
87 </table>
88 <p>
89 <?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 />
90 <?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 />
91 <?php _e('3. ALTER statement will return an error because there is no value returned.', 'wp-dbmanager'); ?>
92 </p>
93 </div>
94 </form>
95