PCCS MySQLDatabase Admin Tool version 1.3.4


/ -> mysqldb_runcmd.php

1  <?php
2   //////////////////////////////////////////////////////////////////////////////////////
3   // coder: cthorn
4   // mysqldb_rumcmd.php
5   //
6  /************************************************************************
7  PCCS MySQLDatabase Admin Tool
8  Copyright (C) 1999 Chauncey Thorn
9 
10  This program is free software; you can redistribute it and/or
11  modify it under the terms of the GNU General Public License
12  as published by the Free Software Foundation; either version 2
13  of the License, or (at your option) any later version.
14 
15  This program is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  GNU General Public License for more details.
19 
20  You should have received a copy of the GNU General Public License
21  along with this program; if not, write to the Free Software
22  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA , USA.
23  **************************************************************************/
24  // updated 10-23-2000
25  // -- moving to a single file for global include files
26    
27  require('mysqldb_app_includes.php');
28     
29     common_header($str_mainTitle);
30 
31  pageTop("PCCS MySQLAdmin Tool","600");
32 
33  if($action == "showindexes"):
34 
35  mysql_select_db($dbname);
36 
37  $res = mysql_query("SHOW INDEX FROM $tblname FROM $dbname") or die(mysql_error());
38 
39  $indexes=mysql_fetch_array($res);
40  print "<table>";
41  print "
42  <tr>
43          <th>Tablename</th>
44          <th>Non_unique</th>
45          <th>Key_namee</th>
46          <th>Seq_in_index</th>
47          <th>Column_name</th>
48          <th>Collation</th>
49          <th>Cardinality</th>
50          <th>Sub_part</th>
51  </tr>";
52  print "<tr>";
53  print "<td>" . $indexes["Table"] ."</td>";
54  print "<td>" . $indexes["Non_unique"] ."</td>";
55  print "<td>" . $indexes["Key_name"] ."</td>";
56  print "<td>" . $indexes["Seq_in_index"] ."</td>";
57  print "<td>" . $indexes["Column_name"] ."</td>";
58  print "<td>" . $indexes["Collation"] ."</td>";
59  echo "<td>" . $indexes["Cardinality"] ."</td>";
60  print "<td>" . $indexes["Sub_part"] ."</td>";
61  print "</tr>";
62  print "</table>";
63  print "<P>";
64  print "<BR><A HREF=mysqldb_info.php?action=tables&dbname=$dbname>Back to
65   Tables</A>";
66  endif;
67 
68 
69  if($action == "analyzetbl"):
70 
71  mysql_select_db($dbname);
72 
73  $res = mysql_query("ANALYZE TABLE $tblname") or die(mysql_error());
74  log_this("DATABASE ACTION: ANALYZE TABLE $tblname","dblog.txt");
75 
76  $indexes=mysql_fetch_array($res);
77  print "<table>";
78  print "<tr><th>Tablename</th><th>Op</th><th>Msg Type</th><th>Msg Text</th</tr>";
79  print "<tr>";
80  print "<td>" . $indexes["Table"] ."</td>";
81  print "<td>" . $indexes["Op"] ."</td>";
82  print "<td>" . $indexes["Msg_type"] ."</td>";
83  print "<td>" . $indexes["Msg_text"] ."</td>";
84  print "</tr></table>";
85  print "<P>";
86  print "<BR><A HREF=mysqldb_info.php?action=tables&dbname=$dbname>Back to
87   Tables</A>";
88  endif;
89 
90  if($action == "check_repair"):
91  mysql_select_db($dbname);
92 
93  $res = mysql_query("CHECK TABLE $tblname");
94  $ch = mysql_fetch_array($res);
95 
96  if($ch["Msg_text"] != "OK") {
97   echo $ch["Msg_text"];
98   $res = mysql_query("REPAIR TABLE $tblname");
99   $fix = mysql_fetch_array($res);
100   
101   if($fix["Msg_text"] != "OK") {
102     echo "ERROR: Unable to repair table" . $fix["Msg_text"];
103     } else {
104     echo "Database table repaired";
105     }
106   } else {
107   echo "Table not damaged it checkout OK!...";
108   echo "<BR><A HREF=mysqldb_info.php?action=tables&dbname=$dbname>Back to
109   Tables</A>";
110   }
111  endif;
112 
113  /***
114  if($action == "data"):
115  // updated
116  // Will be used for displaying query results
117 
118     $result = mysql_db_query($dbname,"SELECT * FROM $tblname");
119     print "<table>";
120     while($value=mysql_fetch_array($result)) {
121       print "<tr bgcolor=CCCCCC>";
122       for($i=0; $i<mysql_num_fields($result); $i++) {
123         print "<td> $value[$i] </td>";
124       }
125       print "</tr>";
126    }
127    print "</table>";
128 
129  endif;
130  ***/
131 
132  if($action == "backuptables"):
133  // updated
134  // have tested code just included it as I was reading the
135  // mysql docs...
136  // haven't defined dump dir yet...
137  // 3.23.xx series
138 
139     $res = mysql_list_tables($dbname);
140     while($row = mysql_fetch_row($res)) {
141     $tablebackupdir = $dbname . $dir;
142     $result = mysql_db_query($dbname, "BACKUP TABLE $row[$i] TO $tablebackupdir");
143     if(!$result) { print "ERROR: ". mysql_error();
144     } else {
145     print "File backupto " . $tablebackupdir;
146     }
147  }
148  endif;
149 
150  if($action == "restoretables"):
151  // updated
152  // have tested code just included it as I was reading the
153  // mysql docs...
154  // haven't defined dump dir yet...
155  // 3.23.xx series
156 
157     $res = mysql_list_tables($dbname);
158     while($row = mysql_fetch_row($res)) {
159     $tablebackupdir = $dbname . $dir;
160     $result = mysql_db_query($dbname, "RESTORE TABLE $row[$i] TO $tablebackupdir");
161     if(!$result) { print "ERROR: ". mysql_error();
162     } else {
163     print "File backupto " . $tablebackupdir;
164     }
165  }
166  endif;
167 
168  // updated
169  // added create database + tables
170 
171  if($action == "createdb"):
172 
173  $res = mysql_create_db($thisdatabase);
174  if(!$res) {
175   print "ERROR: " . mysql_error();
176   } else {
177   // updated
178   // Display a input field for number of tables to create
179   // pass to action=numberoftbls
180   
181   print "Database Created ...<BR>\n";
182   print "<H3>How many Tables do you want in this database?</H3><br>\n";
183   print "<FORM ACTION=$PHP_SELF?action=numberoftbls METHOD=post>\n";
184   print "<INPUT TYPE=hidden name=thisdatabase VALUE=$thisdatabase>\n";
185   print "&nbsp; <INPUT TYPE=text NAME=numoftables SIZE=6>\n";
186   print "&nbsp;&nbsp;<INPUT TYPE=submit VALUE=\"CREATE\">\n";
187   print "</FORM>\n";
188   print "<P>";
189 
190  // update
191  // added code but having problems
192  // will look at later
193  // trying to copy database to another
194 
195  /**
196   print "Or would you like to copy a database to this database ?<P>\n";
197   $listdb = mysql_list_dbs();
198   print "<FORM ACTION=$PHP_SELF?action=copydatabase METHOD=post>";
199   print "Copy &nbsp; <SELECT NAME=thisdatabase>";
200   while($row= mysql_fetch_row($listdb)) {
201   print "<OPTION VALUE=" . $row[0] . ">" . $row[0];
202    }
203   print "</SELECT>\n";
204   print "<INPUT TYPE=hidden NAME=newdbname VALUE=$thisdatabase>\n";
205   print " TO " . $thisdatabase;
206   print "&nbsp; <INPUT TYPE=submit VALUE=\"COPY\">\n";
207   print "</FORM>";
208  **/
209 
210   print "<P><A href=mysqldb_admin.php>Back to Databases</a>\n";
211   }
212 
213  endif;
214 
215  if($action == "numberoftbls"):
216  // updated
217  // Create a textarea for each table
218  // Allow the enter SQL freely MUST know how to create table
219  // Can cut and paste from a database dump or text file
220 
221  print "<H3>Enter the SYNTAX to create tables below...</H3>";
222  print "<FORM ACTION=$PHP_SELF?action=createtables METHOD=post>\n";
223  print "<INPUT TYPE=hidden name=dbname VALUE=$thisdatabase>";
224  for($i=0; $i < $numoftables; $i++) {
225  print "<P><TEXTAREA NAME=thistables[] COLS=55 ROWS=10></TEXTAREA>\n";
226  }
227  print "<P>\n";
228  print "<INPUT TYPE=submit VALUE=\"CREATE TABLES\">\n";
229  print "</FORM><P>\n";
230 
231  endif;
232 
233  if($action == "createtables"):
234  // updated
235  // Create the tables in this database
236  // Count the textarea array from $action == numberoftbls
237  // and create tables using mysql_db_query() function
238 
239  $count = count($thistables);
240  for($i=0; $i< $count; $i++) {
241 
242  // required to remove slashes from create statement
243 
244  $thistables[$i] = stripslashes($thistables[$i]);
245 
246  $res = mysql_db_query($dbname,$thistables[$i]);
247  if (!$res) {
248   print "ERROR " . mysql_error();
249   }
250   else {
251     $result = mysql_list_tables($dbname);
252     $numbercreated = mysql_num_rows($result);
253     print "Tables Created" .$numbercreated ;
254    while($row = mysql_fetch_row($result)) {
255           print $row[0] . "<br>\n";
256     }
257 
258     }
259 
260  }
261 
262 
263  endif;
264 
265  if($action == "copydatabase"):
266  // update
267  // added code but having problems
268  // will look at later
269  // trying to copy database to another
270  // Function to copy database
271  //
272  function copydb($thisdatabase,$newdbname) {
273  global $mysqldbuser, $mysqldbpasswd;
274          $_time = date("H:i:s");
275          $_date = date("Y-m-d");
276          $_admtool = "/usr/local/bin/mysqldump";
277          $_clienttool = "/usr/local/bin/mysql";
278          $par = "--opt -u$mysqldbuser -p$mysqldbpasswd $thisdatabase ";
279          $par2 = "| $_clienttool -u$mysqldbuser -p$mysqldbpasswd $newdbname";
280          $command = "$_admtool $par $par2";
281          passthru($command) or die("FAILED");
282          }
283          
284   copydb($thisdatabase,$newdbname);
285 
286          echo $thisdatabase . "and" . $newdbname;
287                  
288  endif;
289 
290 
291  pageBottom();
292  ?>


Generated: Sat Jan 27 15:40:36 2001 Generated by PHPXref 0.1.2
PCCS-Linux.COM ::ource Advocate Articles catalogue
2000 2002