├── LICENSE ├── README.md ├── ajaxcreatetable.php ├── ajaxfulltext.php ├── ajaximportfile.php ├── ajaxquery.php ├── ajaxsavecolumnedit.php ├── ajaxsaveedit.php ├── ajaxsaveuseredit.php ├── browse.php ├── config.php ├── css ├── common.css ├── navigation.css └── print.css ├── dboverview.php ├── edit.php ├── editcolumn.php ├── edituser.php ├── export.php ├── functions.php ├── home.php ├── images ├── button.png ├── close.png ├── closeHover.png ├── closedArrow.png ├── goto.png ├── info.png ├── infoHover.png ├── initLoad.png ├── loading.gif ├── logo.png ├── openArrow.png ├── schemaHeader.png ├── sortasc.gif ├── sortdesc.gif ├── transparent.png ├── window-button.png ├── window-center.png ├── window-close.png ├── window-header-center.png ├── window-header-left.png ├── window-header-right.png ├── window-resize.png ├── window-shadow-bottom-left.png ├── window-shadow-bottom-right.png ├── window-shadow-bottom.png ├── window-shadow-left.png └── window-shadow-right.png ├── import.php ├── includes ├── browse.php ├── class │ ├── GetTextReader.php │ └── Sql.php └── types.php ├── index.php ├── insert.php ├── js ├── core.js ├── helpers.js ├── mootools-1.2-core.js └── movement.js ├── locale ├── ar_DZ.pot ├── bg_BG.pot ├── bn_BD.pot ├── ca_AD.pot ├── cs_CZ.pot ├── da_DK.pot ├── de_DE.pot ├── el_GR.pot ├── en_US.pot ├── eo_EO.pot ├── es_AR.pot ├── es_ES.pot ├── et_EE.pot ├── fa_IR.pot ├── fi_FI.pot ├── fr_FR.pot ├── gl_ES.pot ├── he_IL.pot ├── hr_HR.pot ├── hu_HU.pot ├── id_ID.pot ├── it_IT.pot ├── ja_JP.pot ├── ko_KR.pot ├── lo_LA.pot ├── lt_LT.pot ├── lv_LV.pot ├── ms_ID.pot ├── nl_NL.pot ├── no_NO.pot ├── pl_PL.pot ├── pt_BR.pot ├── pt_PT.pot ├── ro_RO.pot ├── ru_RU.pot ├── sk_SK.pot ├── sl_SL.pot ├── sp_RS.pot ├── sq_AL.pot ├── sr_RS.pot ├── sv_SE.pot ├── th_TH.pot ├── tl_PH.pot ├── tr_TR.pot ├── uk_UA.pot ├── vi_VN.pot ├── zh_CN.pot └── zh_TW.pot ├── login.php ├── logout.php ├── query.php ├── serve.php ├── structure.php ├── themes ├── bittersweet │ ├── css │ │ ├── ie.css │ │ └── main.css │ └── images │ │ ├── header.png │ │ └── initLoad-dark.png └── classic │ ├── css │ ├── ie.css │ └── main.css │ └── images │ ├── corner-bl.png │ ├── corner-br.png │ ├── corner-tl.png │ ├── corner-tr.png │ ├── header.png │ └── shading.png └── users.php /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2016 Frecuencio 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | sqlbuddy-php7 2 | ============= 3 | 4 | --- 5 | 6 | 7 | SQL Buddy fork with compatibility for PHP 5.5+ (PHP 7 Included). Plus, new MySQL column types. 8 | 9 | Original page: [http://sqlbuddy.com/](http://sqlbuddy.com/) 10 | 11 | --- 12 | # How to install: 13 | 14 | Simply copy the 'sqlbuddy' folder onto your server. Easy peasy. 15 | 16 | --- 17 | # Why i'm not giving support to SQL Buddy anymore? 18 | 19 | First of all, most of the code was written by Calvin Lough back in 2011. He did a really nice work, but nowadays, it surely contains code not optimized and unsafe. 20 | 21 | This version was tested in php 7.4 and seems working fine, but i suggest migrating to another up-to-date solution. -------------------------------------------------------------------------------- /ajaxcreatetable.php: -------------------------------------------------------------------------------- 1 | 13 | Reviewed : 2016 Carlos Martín Arnillas 14 | 15 | */ 16 | 17 | include "functions.php"; 18 | 19 | loginCheck(); 20 | 21 | if (isset($db)) 22 | $conn->selectDB($db); 23 | 24 | if (isset($_POST['query'])) { 25 | 26 | $queryList = splitQueryText($_POST['query']); 27 | 28 | foreach ($queryList as $query) { 29 | $sql = $conn->query($query) or ($dbError = $conn->error()); 30 | } 31 | 32 | if (isset($dbError)) { 33 | echo $dbError; 34 | } 35 | 36 | } 37 | 38 | ?> 39 | -------------------------------------------------------------------------------- /ajaxfulltext.php: -------------------------------------------------------------------------------- 1 | 13 | Reviewed : 2016 Carlos Martín Arnillas 14 | 15 | */ 16 | 17 | include "functions.php"; 18 | 19 | loginCheck(); 20 | 21 | if (isset($db)) 22 | $conn->selectDB($db); 23 | 24 | if (isset($_POST['query'])) { 25 | 26 | $queryList = splitQueryText($_POST['query']); 27 | 28 | foreach ($queryList as $query) { 29 | $sql = $conn->query($query); 30 | } 31 | } 32 | 33 | $structureSql = $conn->describeTable($table); 34 | 35 | while ($structureRow = $conn->fetchAssoc($structureSql)) { 36 | $types[$structureRow['Field']] = $structureRow['Type']; 37 | } 38 | 39 | 40 | if ($conn->isResultSet($sql)) { 41 | 42 | $row = $conn->fetchAssoc($sql); 43 | 44 | foreach ($row as $key => $value) { 45 | echo "
" . $key . "
"; 46 | echo "
"; 47 | 48 | $curtype = $types[$key]; 49 | 50 | if (strpos(" ", $curtype) > 0) { 51 | $curtype = substr($curtype, 0, strpos(" ", $curtype)); 52 | } 53 | 54 | if ($value && isset($binaryDTs) && in_array($curtype, $binaryDTs)) { 55 | echo '(' . __("binary data") . ')'; 56 | } else { 57 | echo nl2br(htmlentities($value, ENT_QUOTES, 'UTF-8')); 58 | } 59 | 60 | echo "
"; 61 | } 62 | } 63 | 64 | ?> 65 | -------------------------------------------------------------------------------- /ajaximportfile.php: -------------------------------------------------------------------------------- 1 | 13 | Reviewed : 2016 Carlos Martín Arnillas 14 | 15 | */ 16 | 17 | include "functions.php"; 18 | 19 | loginCheck(); 20 | 21 | if (isset($db)) 22 | $conn->selectDB($db); 23 | 24 | function stripCommentLines($in) { 25 | if (substr($in, 0, 2) == "--") 26 | $in = ''; 27 | 28 | return $in; 29 | } 30 | 31 | if (isset($_POST) || isset($_FILES)) { 32 | 33 | if (isset($_FILES['INPUTFILE']['tmp_name'])) 34 | $file = $_FILES['INPUTFILE']['tmp_name']; 35 | 36 | if (isset($_POST['FORMAT'])) 37 | $format = $_POST['FORMAT']; 38 | 39 | if (!(isset($format) && $format == "CSV")) 40 | $format = "SQL"; 41 | 42 | if (isset($_POST['IGNOREFIRST'])) 43 | $ignoreFirst = $_POST['IGNOREFIRST']; 44 | 45 | $first = true; 46 | 47 | // for csv 48 | if (isset($format) && $format == "CSV" && isset($table)) { 49 | $columnCount = 0; 50 | 51 | $structureSQL = $conn->describeTable($table); 52 | 53 | if ($conn->isResultSet($structureSQL)) { 54 | while ($structureRow = $conn->fetchAssoc($structureSQL)) { 55 | $columnCount++; 56 | } 57 | } 58 | } 59 | 60 | $insertCount = 0; 61 | $skipCount = 0; 62 | 63 | if (isset($file) && is_uploaded_file($file)) { 64 | if (isset($format) && $format == "SQL") { 65 | $lines = file($file); 66 | 67 | // the file() function doesn't handle mac line endings correctly 68 | if (sizeof($lines) == 1 && strpos($lines[0], "\r") > 0) { 69 | $lines = explode("\r", $lines[0]); 70 | } 71 | 72 | $commentFree = array_map("stripCommentLines", $lines); 73 | 74 | $contents = trim(implode('', $commentFree)); 75 | 76 | $statements = splitQueryText($contents); 77 | } else { 78 | $statements = file($file); 79 | 80 | // see previous comment 81 | if (sizeof($statements) == 1 && strpos($statements[0], "\r") > 0) { 82 | $statements = explode("\r", $statements[0]); 83 | } 84 | } 85 | 86 | foreach ($statements as $statement) { 87 | $statement = trim($statement); 88 | 89 | if ($statement) { 90 | if (isset($format) && $format == "SQL") { 91 | $importQuery = $conn->query($statement) or ($dbErrors[] = $conn->error()); 92 | 93 | $affected = (int)($conn->affectedRows($importQuery)); 94 | $insertCount += $affected; 95 | } else if (isset($format) && $format == "CSV" && isset($table)) { 96 | if (!(isset($ignoreFirst) && $first)) { 97 | preg_match_all('/"(([^"]|"")*)"/i', $statement, $matches); 98 | 99 | $rawValues = $matches[1]; 100 | 101 | for ($i=0; $iescapeString($rawValues[$i]); 104 | } 105 | 106 | $values = implode("','", $rawValues); 107 | 108 | // make sure that the counts match up 109 | if (sizeof($rawValues) == $columnCount) { 110 | 111 | $importQuery = $conn->query("INSERT INTO `$table` VALUES ('$values')") or ($dbErrors[] = $conn->error()); 112 | 113 | $affected = (int)($conn->affectedRows($importQuery)); 114 | 115 | $insertCount += $affected; 116 | } else { 117 | $skipCount++; 118 | } 119 | } 120 | $first = false; 121 | } 122 | } 123 | } 124 | } 125 | 126 | $message = ""; 127 | 128 | if (!isset($statements)) { 129 | $message .= __("Either the file could not be read or it was empty") . "
"; 130 | } else if ($format == "SQL") { 131 | $message .= sprintf(__p("%d statement was executed from the file", "%d statements were executed from the file", $insertCount), $insertCount) . ".
"; 132 | } else if ($format == "CSV") { 133 | if (isset($insertCount) && $insertCount > 0) { 134 | $message .= sprintf(__p("%d row was inserted into the database from the file", "%d rows were inserted into the database from the file", $insertCount), $insertCount) . ".
"; 135 | } 136 | if (isset($skipCount) && $skipCount > 0) { 137 | $message .= sprintf(__p("%d row had to be skipped because the number of values was incorrect", "%d rows had to be skipped because the number of values was incorrect", $skipCount), $skipCount) . ".
"; 138 | } 139 | } 140 | 141 | if (isset($dbErrors)) { 142 | $message .= __("The following errors were reported") . ":
"; 143 | foreach ($dbErrors as $merr) { 144 | $message .= " - " . $merr . "
"; 145 | } 146 | } 147 | 148 | ?> 150 | 151 | 152 | 153 | 154 | 155 | 161 | 162 | 163 | 164 | 169 | -------------------------------------------------------------------------------- /ajaxquery.php: -------------------------------------------------------------------------------- 1 | 13 | Reviewed : 2016 Carlos Martín Arnillas 14 | 15 | */ 16 | 17 | include "functions.php"; 18 | 19 | loginCheck(); 20 | 21 | if (isset($db)) 22 | $conn->selectDB($db); 23 | 24 | if (isset($_POST['query'])) { 25 | $queryList = splitQueryText($_POST['query']); 26 | 27 | foreach ($queryList as $query) { 28 | $sql = $conn->query($query); 29 | } 30 | } 31 | 32 | //return the first field from the first row 33 | if (!isset($_POST['silent']) && $conn->isResultSet($sql)) { 34 | $row = $conn->fetchArray($sql); 35 | echo nl2br(htmlentities($row[0], ENT_QUOTES, 'UTF-8')); 36 | } 37 | 38 | ?> 39 | -------------------------------------------------------------------------------- /ajaxsavecolumnedit.php: -------------------------------------------------------------------------------- 1 | 13 | Reviewed : 2016 Carlos Martín Arnillas 14 | 15 | */ 16 | 17 | include "functions.php"; 18 | 19 | loginCheck(); 20 | 21 | if (isset($db)) 22 | $conn->selectDB($db); 23 | 24 | if (isset($_POST['runQuery'])) { 25 | $query = $_POST['runQuery']; 26 | 27 | $conn->query($query) or ($dbError = $conn->error()); 28 | 29 | echo "{\n"; 30 | echo " \"formupdate\": \"" . $_GET['form'] . "\",\n"; 31 | echo " \"errormess\": \""; 32 | if (isset($dbError)) 33 | echo $dbError; 34 | echo "\"\n"; 35 | echo '}'; 36 | 37 | } 38 | 39 | ?> 40 | -------------------------------------------------------------------------------- /ajaxsaveedit.php: -------------------------------------------------------------------------------- 1 | 13 | Reviewed : 2016 Carlos Martín Arnillas 14 | 15 | */ 16 | 17 | include "functions.php"; 18 | 19 | loginCheck(); 20 | 21 | if (isset($db)) 22 | $conn->selectDB($db); 23 | 24 | if ($_POST && isset($table)) { 25 | 26 | $insertChoice = ""; 27 | 28 | if (isset($_POST['SB_INSERT_CHOICE'])) { 29 | $insertChoice = $_POST['SB_INSERT_CHOICE']; 30 | } 31 | 32 | $structureSql = $conn->describeTable($table); 33 | 34 | while ($structureRow = $conn->fetchAssoc($structureSql)) { 35 | $pairs[$structureRow['Field']] = ''; 36 | $types[$structureRow['Field']] = $structureRow['Type']; 37 | $nulls[$structureRow['Field']] = (isset($structureRow['Null'])) ? $structureRow['Null'] : "YES"; 38 | } 39 | 40 | foreach ($_POST as $key=>$value) { 41 | if ($key != "SB_INSERT_CHOICE") { 42 | if (is_array($value)) { 43 | $value = implode(",", $value); 44 | } 45 | 46 | $pairs[$key] = $conn->escapeString($value); 47 | } 48 | } 49 | 50 | if (isset($pairs)) { 51 | 52 | if ($insertChoice != "INSERT") { 53 | $updates = ""; 54 | 55 | foreach ($pairs as $keyname=>$value) { 56 | if (isset($types) && substr($value, 0, 2) == "0x" && isset($binaryDTs) && in_array($types[$keyname], $binaryDTs)) { 57 | $updates .= "`" . $keyname . "`=" . $value . ","; 58 | } else if (!$value && !($value != '' && (int)$value == 0) && $nulls[$keyname] == "YES") { 59 | $updates .= "`" . $keyname . "`=NULL,"; 60 | } else { 61 | $updates .= "`" . $keyname . "`='" . $value . "',"; 62 | } 63 | } 64 | 65 | $updates = substr($updates, 0, -1); 66 | 67 | if (isset($_GET['queryPart'])) { 68 | $queryPart = $_GET['queryPart']; 69 | } 70 | else { 71 | $queryPart = ""; 72 | } 73 | 74 | $query = "UPDATE `$table` SET " . $updates . " " . $queryPart; 75 | 76 | } else { 77 | $columns = ""; 78 | $values = ""; 79 | 80 | foreach ($pairs as $keyname=>$value) { 81 | 82 | $columns .= "`" . $keyname . "`,"; 83 | 84 | if (isset($types) && substr($value, 0, 2) == "0x" && isset($binaryDTs) && in_array($types[$keyname], $binaryDTs)) { 85 | $values .= $value . ","; 86 | } else { 87 | $values .= "'" . $value . "',"; 88 | } 89 | 90 | } 91 | 92 | $columns = substr($columns, 0, -1); 93 | $values = substr($values, 0, -1); 94 | $query = "INSERT INTO `$table` ($columns) VALUES ($values)"; 95 | } 96 | 97 | $conn->query($query) or ($dbError = $conn->error()); 98 | 99 | echo "{\n"; 100 | echo " \"formupdate\": \"" . $_GET['form'] . "\",\n"; 101 | echo " \"errormess\": \""; 102 | if (isset($dbError)) 103 | echo $dbError; 104 | echo "\"\n"; 105 | echo '}'; 106 | 107 | } 108 | } 109 | 110 | ?> 111 | -------------------------------------------------------------------------------- /ajaxsaveuseredit.php: -------------------------------------------------------------------------------- 1 | 13 | Reviewed : 2016 Carlos Martín Arnillas 14 | 15 | */ 16 | 17 | include "functions.php"; 18 | 19 | loginCheck(); 20 | 21 | $conn->selectDB("mysql"); 22 | 23 | function removeAdminPrivs($priv) { 24 | if ($priv == "FILE" || $priv == "PROCESS" || $priv == "RELOAD" || $priv == "SHUTDOWN" || $priv == "SUPER") 25 | return false; 26 | else 27 | return true; 28 | } 29 | 30 | if (isset($_GET['user'])) 31 | $user = $_GET['user']; 32 | 33 | if (isset($_POST['NEWPASS'])) 34 | $newPass = $_POST['NEWPASS']; 35 | 36 | if (isset($_POST['CHOICE'])) 37 | $choice = $_POST['CHOICE']; 38 | 39 | if (isset($_POST['ACCESSLEVEL'])) 40 | $accessLevel = $_POST['ACCESSLEVEL']; 41 | else 42 | $accessLevel = "GLOBAL"; 43 | 44 | if ($accessLevel != "LIMITED") 45 | $accessLevel = "GLOBAL"; 46 | 47 | if (isset($_POST['DBLIST'])) 48 | $dbList = $_POST['DBLIST']; 49 | else 50 | $dbList = array(); 51 | 52 | if (isset($_POST['PRIVILEGES'])) 53 | $privileges = $_POST['PRIVILEGES']; 54 | else 55 | $privileges = array(); 56 | 57 | if (isset($_POST['GRANTOPTION'])) 58 | $grantOption = $_POST['GRANTOPTION']; 59 | 60 | if (isset($user) && ($accessLevel == "GLOBAL" || ($accessLevel == "LIMITED" && sizeof($dbList) > 0))) { 61 | 62 | if ($choice == "ALL") { 63 | $privList = "ALL"; 64 | } else { 65 | if (isset($privileges) && count($privileges) > 0) 66 | $privList = implode(", ", $privileges); 67 | else 68 | $privList = "USAGE"; 69 | 70 | if (sizeof($privileges) > 0) { 71 | if ($accessLevel == "LIMITED") { 72 | $privileges = array_filter($privileges, "removeAdminPrivs"); 73 | } 74 | 75 | $privList = implode(", ", $privileges); 76 | } else { 77 | $privList = "USAGE"; 78 | } 79 | 80 | } 81 | 82 | $split = explode("@", $user); 83 | 84 | if (isset($split[0])) 85 | $name = $split[0]; 86 | 87 | if (isset($split[1])) 88 | $host = $split[1]; 89 | 90 | if (isset($name) && isset($host)) { 91 | $user = "'" . $name . "'@'" . $host . "'"; 92 | 93 | if ($accessLevel == "LIMITED") { 94 | $conn->query("DELETE FROM `db` WHERE `User`='$name' AND `Host`='$host'"); 95 | 96 | foreach ($dbList as $theDb) { 97 | $query = "GRANT " . $privList . " ON `$theDb`.* TO " . $user; 98 | 99 | if (isset($grantOption)) 100 | $query .= " WITH GRANT OPTION"; 101 | 102 | $conn->query($query) or ($dbError = $conn->error()); 103 | } 104 | } else { 105 | $conn->query("REVOKE ALL PRIVILEGES ON *.* FROM " . $user); 106 | $conn->query("REVOKE GRANT OPTION ON *.* FROM " . $user); 107 | 108 | $query = "GRANT " . $privList . " ON *.* TO " . $user; 109 | 110 | if (isset($grantOption)) 111 | $query .= " WITH GRANT OPTION"; 112 | 113 | $conn->query($query) or ($dbError = $conn->error()); 114 | } 115 | 116 | if (isset($newPass)) 117 | $conn->query("SET PASSWORD FOR '$name'@'$host' = PASSWORD('$newPass')") or ($dbError = $conn->error()); 118 | 119 | $conn->query("FLUSH PRIVILEGES") or ($dbError = $conn->error()); 120 | 121 | echo "{\n"; 122 | echo " \"formupdate\": \"" . $_GET['form'] . "\",\n"; 123 | echo " \"errormess\": \""; 124 | if (isset($dbError)) 125 | echo $dbError; 126 | echo "\"\n"; 127 | echo '}'; 128 | } 129 | } 130 | 131 | ?> 132 | -------------------------------------------------------------------------------- /browse.php: -------------------------------------------------------------------------------- 1 | 13 | Reviewed : 2016 Carlos Martín Arnillas 14 | 15 | */ 16 | 17 | include "functions.php"; 18 | 19 | loginCheck(); 20 | 21 | requireDatabaseAndTableBeDefined(); 22 | 23 | if (isset($db)) 24 | $conn->selectDB($db); 25 | 26 | //run delete queries 27 | 28 | if (isset($_POST['runQuery'])) { 29 | $runQuery = $_POST['runQuery']; 30 | 31 | $queryList = splitQueryText($runQuery); 32 | foreach ($queryList as $query) { 33 | $conn->query($query); 34 | } 35 | } 36 | 37 | $query = "SELECT * FROM `$table`"; 38 | 39 | $queryTable = $table; 40 | 41 | if (isset($_POST['s'])) 42 | $start = (int)($_POST['s']); 43 | else 44 | $start = 0; 45 | 46 | if (isset($_POST['sortKey'])) 47 | $sortKey = $_POST['sortKey']; 48 | 49 | if (isset($_POST['sortDir'])) 50 | $sortDir = $_POST['sortDir']; 51 | else if (isset($sortKey)) 52 | $sortDir = "ASC"; 53 | 54 | if (isset($_POST['view']) && $_POST['view'] == "1") 55 | $view = 1; 56 | else 57 | $view = 0; 58 | 59 | if (isset($sortKey) && $sortKey != "" && isset($sortDir) && $sortDir != "") { 60 | $sort = "ORDER BY `" . $sortKey . "` " . $sortDir; 61 | } else { 62 | $sort = ""; 63 | } 64 | 65 | require "includes/browse.php"; 66 | 67 | ?> 68 | -------------------------------------------------------------------------------- /config.php: -------------------------------------------------------------------------------- 1 | 13 | Reviewed : 2016 Carlos Martín Arnillas 14 | 15 | */ 16 | 17 | 18 | /* The values below are for the login.php page */ 19 | 20 | $sbconfig['DefaultAdapter'] = "mysql"; 21 | $sbconfig['DefaultHost'] = "localhost"; 22 | $sbconfig['DefaultUser'] = "root"; 23 | 24 | /* 25 | * If you want to enable automatic login, you can include your password below. To 26 | * automatically connect to SQLite, include the filename of the database instead. 27 | * Note: This is generally not recommended because it means that anyone with the 28 | * proper url will have access to your data. It should only be used on machines 29 | * that are not accessible from the internet (local testing boxes) or if you have 30 | * set up some other form of authentication. Use as your own discretion. 31 | */ 32 | 33 | // MySQL 34 | // $sbconfig['DefaultPass'] = ""; 35 | 36 | // SQLite 37 | // $sbconfig['DefaultDatabase'] = ""; 38 | 39 | /* 40 | * By default, when you view the homepage of your SQL Buddy installation, a check is 41 | * performed to see if a newer version of the application is available. No personal 42 | * information is sent about your installation and the response from the server is sent 43 | * as plain text. If, for some reason, you want to disable this behaviour, set this option 44 | * to true to disable automatic checking for updates. To learn about new versions, you can 45 | * always check the projects website at http://www.sqlbuddy.com/ 46 | */ 47 | 48 | $sbconfig['EnableUpdateCheck'] = true; 49 | 50 | /* 51 | * This controls how many rows are displayed at once on the browse tab. If you are on a local 52 | * machine or have a fast internet connection, you could increase this value. 53 | */ 54 | 55 | $sbconfig['RowsPerPage'] = 100; 56 | 57 | /* 58 | * When set to true, the server will attempt to compress all content before it is sent to the 59 | * browser. Although unlikely, there is a chance that using gzip will cause issues on certain setups. 60 | * If you are having trouble getting pages to load properly, you could try disabling gzip. 61 | */ 62 | 63 | $sbconfig['EnableGzip'] = true; 64 | 65 | ?> 66 | -------------------------------------------------------------------------------- /css/navigation.css: -------------------------------------------------------------------------------- 1 | .dblistheader { 2 | padding: 0px 0px 0px 7px; 3 | outline: none; 4 | text-transform: uppercase; 5 | font-size: 10px; 6 | color: rgb(175, 175, 175); 7 | } 8 | 9 | .dblist { 10 | width: 100%; 11 | line-height: 17px; 12 | padding-bottom: 6px; 13 | } 14 | .dblist ul { 15 | padding: 0px; 16 | } 17 | .dblist ul li { 18 | list-style-type: none; 19 | } 20 | .dblist ul li a { 21 | display: block; 22 | outline: none; 23 | border-width: 1px 0 1px 1px; 24 | border-style: solid; 25 | border-color: transparent; 26 | } 27 | .dblist ul li a .menutext { 28 | padding: 1px 6px 0px 0px; 29 | margin-left: 16px; 30 | border: 0; 31 | } 32 | .dblist ul li a .menutoggler { 33 | width: 12px; 34 | height: 14px; 35 | margin: 3px 4px 0px 2px; 36 | float: left; 37 | background: transparent url(../images/closedArrow.png) no-repeat 4px 3px; 38 | } 39 | .dblist ul li a .menuicon { 40 | height: 14px; 41 | margin: 0px 5px 0px 6px; 42 | float: left; 43 | font-size: 10px; 44 | padding-top: 1px; 45 | } 46 | .dblist ul li.expanded a .menutoggler{ 47 | background: transparent url(../images/openArrow.png) no-repeat 3px 3px; 48 | } 49 | .dblist ul li.expanded .sublist { 50 | display: block; 51 | } 52 | 53 | .sublist { 54 | border: 0px !important; 55 | overflow: hidden; 56 | } 57 | .sublist li a { 58 | padding: 1px 6px 0px 22px !important; 59 | margin-left: 7px; 60 | overflow-x: hidden; 61 | } 62 | .sublist li.loading a { 63 | background: url(../images/loading.gif) no-repeat 0 0 !important; 64 | } 65 | .subcount { 66 | padding-left: 5px; 67 | font-size: 11px; 68 | } 69 | 70 | #toptabs { 71 | padding-top: 7px; 72 | float: left; 73 | } 74 | #toptabs ul { 75 | padding: 0; 76 | } 77 | #toptabs ul li { 78 | list-style-type: none; 79 | float: left; 80 | } 81 | #toptabs ul li a { 82 | margin: 0 5px 0 15px; 83 | outline: none; 84 | } 85 | #toptabs ul li a .rowcount { 86 | font-weight: normal; 87 | padding-left: 3px; 88 | } 89 | #toptabs ul li.selected a { 90 | cursor: default; 91 | } 92 | #toptabs ul li.deactivated a { 93 | cursor: default; 94 | } -------------------------------------------------------------------------------- /css/print.css: -------------------------------------------------------------------------------- 1 | #header { 2 | display: none; 3 | } 4 | 5 | .inputbutton, .inputbutton:active { 6 | background: default !important; 7 | border: default !important; 8 | line-height: inherit !important; 9 | width: auto !important; 10 | height: auto !important; 11 | } 12 | 13 | #innercontent a { 14 | color: #3A6D96 !important; 15 | } 16 | 17 | .leftchecks, .emptyvoid { 18 | display: none !important; 19 | } 20 | .gridscroll, .gridheader { 21 | max-height: none !important; 22 | max-width: none !important; 23 | overflow: none !important; 24 | } 25 | .withinfo, .withchecks { 26 | margin-left: 0 !important; 27 | } -------------------------------------------------------------------------------- /dboverview.php: -------------------------------------------------------------------------------- 1 | 13 | Reviewed : 2016 Carlos Martín Arnillas 14 | 15 | */ 16 | 17 | include "functions.php"; 18 | 19 | loginCheck(); 20 | 21 | if (isset($db)) { 22 | 23 | $conn->selectDB($db); 24 | 25 | //run delete queries 26 | 27 | if (isset($_POST['runQuery'])) { 28 | 29 | $runQuery = $_POST['runQuery']; 30 | 31 | $queryList = splitQueryText($runQuery); 32 | 33 | foreach ($queryList as $query) { 34 | $query = trim($query); 35 | 36 | if ($query != "") { 37 | $conn->query($query) or ($dbError = $conn->error()); 38 | 39 | // make a list of the tables that were dropped/emptied 40 | if (substr($query, 0, 10) == "DROP TABLE") 41 | $droppedList[] = substr($query, 12, -1); 42 | 43 | if (substr($query, 0, 10) == "TRUNCATE `") 44 | $emptiedList[] = substr($query, 10, -1); 45 | 46 | if (substr($query, 0, 13) == "DELETE FROM '") 47 | $emptiedList[] = substr($query, 13, -1); 48 | 49 | } 50 | } 51 | } 52 | 53 | // if tables were dropped, remove them from the side menu 54 | if (isset($droppedList) && isset($db)) { 55 | ?> 56 | 57 | 76 | 77 | 83 | 84 | 96 | 97 | '; 103 | echo __("Error performing operation"); 104 | echo '

' . $dbError . '

'; 105 | } 106 | 107 | ?> 108 | 109 | 110 | 111 | 487 |
112 | 113 | listTables(); 116 | 117 | if ($conn->isResultSet($tableSql)) { 118 | 119 | echo '
'; 120 | 121 | echo ''; 122 | echo ''; 123 | echo ''; 131 | echo ''; 132 | echo '
'; 124 | 125 | echo __("Select") . ':  ' . __("All") . '  ' . __("None") . ''; 126 | echo '     ' . __("With selected") . ':  ' . __("Empty") . '  ' . __("Drop") . ''; 127 | 128 | echo '  ' . __("Optimize") . ''; 129 | 130 | echo '
'; 133 | 134 | echo '
'; 135 | 136 | echo '
 
'; 137 | 138 | echo '
'; 139 | echo '
'; 140 | echo ''; 141 | echo ''; 142 | echo ''; 143 | echo ''; 144 | echo ''; 145 | echo ''; 146 | 147 | if (isset($charsetList) && isset($collationList)) { 148 | echo ''; 149 | echo ''; 150 | echo ''; 151 | echo ''; 152 | } else{ 153 | echo ''; 154 | echo ''; 155 | } 156 | 157 | echo ''; 158 | echo ''; 159 | echo '
' . __("Table") . '
' . __("Rows") . '
' . __("Charset") . '
' . __("Overhead") . '
' . __("Overhead") . '
 
'; 160 | echo '
'; 161 | echo '
'; 162 | 163 | echo '
'; 164 | 165 | $m = 0; 166 | 167 | while ($tableRow = $conn->fetchArray($tableSql)) { 168 | echo '
'; 176 | } 177 | 178 | echo '
'; 179 | 180 | $tableSql = $conn->listTables(); 181 | 182 | echo '
'; 183 | 184 | $m = 0; 185 | 186 | while ($tableRow = $conn->fetchArray($tableSql)) { 187 | 188 | $rowCount = $conn->tableRowCount($tableRow[0]); 189 | 190 | $infoSql = $conn->query("SHOW TABLE STATUS LIKE '" . $tableRow[0] . "'"); 191 | $infoRow = $conn->fetchAssoc($infoSql); 192 | 193 | $overhead = $infoRow["Data_free"]; 194 | 195 | $formattedOverhead = ""; 196 | 197 | if ($overhead > 0){ 198 | $formattedOverhead = memoryFormat($overhead); 199 | } 200 | 201 | echo '
'; 208 | echo ''; 209 | echo ''; 210 | echo ''; 211 | echo ''; 212 | 213 | if (isset($collationList) && array_key_exists("Collation", $infoRow)) { 214 | echo ''; 215 | echo ''; 216 | } else{ 217 | echo ''; 218 | } 219 | 220 | echo ''; 221 | echo '
' . $tableRow[0] . '
' . number_format($rowCount) . '
' . $collationList[$infoRow['Collation']] . '
' . $formattedOverhead . '
' . $formattedOverhead . '
'; 222 | echo '
'; 223 | 224 | $m++; 225 | } 226 | 227 | echo '
'; 228 | echo '
'; 229 | 230 | echo '
'; 231 | 232 | } 233 | 234 | ?> 235 | 236 |
237 |

238 | 239 | 240 |
241 | 242 | query("SHOW VARIABLES LIKE 'character_set_database'"); 248 | 249 | if ($conn->isResultSet($currentCharSql)) { 250 | $currentChar = $conn->result($currentCharSql, 0, "Value"); 251 | } 252 | 253 | ?> 254 | 255 |
256 |

257 | 258 |
259 |
260 | 261 | 262 | "; 265 | echo ""; 268 | echo ""; 281 | echo ''; 284 | echo ""; 285 | 286 | ?> 287 | 288 |
"; 266 | echo __("Charset") . ":"; 267 | echo ""; 269 | echo ""; 280 | echo "'; 282 | echo ''; 283 | echo '
289 |
290 |
291 | 292 | 297 | 298 | 299 | 300 |
301 |

302 | 303 |
304 | 305 | 306 | 309 | 312 | 313 | "; 317 | echo ""; 320 | echo ""; 333 | echo ""; 334 | } 335 | 336 | if (isset($enginesList)) { 337 | echo ""; 338 | echo ""; 341 | echo ""; 356 | echo ""; 357 | } 358 | 359 | ?> 360 | 361 | 364 | 365 |
307 | : 308 | 310 | 311 |
"; 318 | echo __("Charset") . ":"; 319 | echo ""; 321 | echo ""; 332 | echo "
"; 339 | echo __("Engine") . ":"; 340 | echo ""; 342 | echo ""; 355 | echo "
362 | : 363 |
366 |
367 | 368 |
369 | 370 | 371 | 375 | 376 | 377 | 380 | 383 | 386 | 397 | 398 | 399 | 402 | 405 | 408 | 409 | 410 | 413 | 416 | 419 | 427 | 428 | 429 | 432 | 435 | "; 439 | echo __("Charset") . ":"; 440 | echo ""; 441 | echo ""; 449 | } else { 450 | echo ""; 451 | echo ""; 452 | } 453 | 454 | ?> 455 | 456 | 457 | 460 | 466 | 467 |
372 | <> 373 | 374 |
378 | : 379 | 381 | 382 | 384 | : 385 | 387 | 396 |
411 | : 412 | 414 | 415 | 417 | : 418 | 420 | 426 |
430 | : 431 | 433 | 434 | "; 442 | echo ""; 448 | echo "
458 | : 459 | 461 | 462 | 463 | 464 | 465 |
468 |
469 | 470 |
471 | 472 | 473 | 474 | 477 | 480 | 481 |
475 | " /> 476 | 478 |
479 |
482 |
483 | 484 |
485 | 486 |
488 | 489 | 492 | 493 | 498 | 499 |
500 |

501 |

502 |
503 | 504 | 510 | -------------------------------------------------------------------------------- /edit.php: -------------------------------------------------------------------------------- 1 | 13 | Reviewed : 2016 Carlos Martín Arnillas 14 | 15 | */ 16 | 17 | include "functions.php"; 18 | 19 | loginCheck(); 20 | 21 | requireDatabaseAndTableBeDefined(); 22 | 23 | if (isset($db)) 24 | $conn->selectDB($db); 25 | 26 | if (isset($table)) 27 | $structureSql = $conn->describeTable($table); 28 | 29 | if (isset($_POST['editParts'])) { 30 | $editParts = $_POST['editParts']; 31 | $editParts = explode("; ", $editParts); 32 | 33 | $totalParts = count($editParts); 34 | $counter = 0; 35 | 36 | $firstField = true; 37 | 38 | ?> 39 | 46 | 55 | 56 |
57 | 58 | 59 | isResultSet($structureSql)) { 62 | 63 | $dataSql = $conn->query("SELECT * FROM `" . $table . "` " . $part); 64 | $dataRow = $conn->fetchAssoc($dataSql); 65 | 66 | while ($structureRow = $conn->fetchAssoc($structureSql)) { 67 | 68 | preg_match("/^([a-z]+)(.([0-9]+).)?(.*)?$/", $structureRow['Type'], $matches); 69 | 70 | $curtype = $matches[1]; 71 | $cursizeQuotes = $matches[2]; 72 | $cursize = $matches[3]; 73 | $curextra = $matches[4]; 74 | 75 | echo ''; 76 | echo ''; 81 | echo ''; 82 | echo ''; 83 | echo ' 138 | 139 | 140 | describeTable($table); 144 | 145 | } 146 | ?> 147 | 148 | 152 | 153 | 154 | 157 | 158 |
'; 77 | if ($structureRow['Key'] == 'PRI') echo ''; 78 | echo $structureRow['Field']; 79 | if ($structureRow['Key'] == 'PRI') echo ''; 80 | echo " " . $curtype . $cursizeQuotes . ' ' . $structureRow['Extra'] . '
'; 84 | 85 | $showLargeEditor[] = "text"; 86 | $showLargeEditor[] = "mediumtext"; 87 | $showLargeEditor[] = "longtext"; 88 | 89 | if (in_array($curtype, $showLargeEditor)) { 90 | echo ''; 91 | } 92 | elseif ($curtype == "enum") { 93 | $trimmed = substr($structureRow['Type'], 6, -2); 94 | $listOptions = explode("','", $trimmed); 95 | echo ''; 105 | } 106 | elseif ($curtype == "set") { 107 | $trimmed = substr($structureRow['Type'], 5, -2); 108 | $listOptions = explode("','", $trimmed); 109 | foreach ($listOptions as $option) { 110 | $id = $option . rand(1, 1000); 111 | echo '
'; 117 | } 118 | } else { 119 | echo ''; 131 | } 132 | 133 | $firstField = false; 134 | 135 | ?> 136 | 137 |
149 |
150 | 151 |
155 | " />   156 |
159 |
160 | 161 | 162 | 173 | -------------------------------------------------------------------------------- /editcolumn.php: -------------------------------------------------------------------------------- 1 | 13 | Reviewed : 2016 Carlos Martín Arnillas 14 | 15 | */ 16 | 17 | include "functions.php"; 18 | 19 | loginCheck(); 20 | 21 | requireDatabaseAndTableBeDefined(); 22 | 23 | if (isset($db)) 24 | $conn->selectDB($db); 25 | 26 | if (isset($db)) 27 | $structureSql = $conn->query("SHOW FULL FIELDS FROM `$table`"); 28 | 29 | if (isset($_POST['editParts']) && $conn->isResultSet($structureSql)) { 30 | 31 | $editParts = $_POST['editParts']; 32 | 33 | $editParts = explode("; ", $editParts); 34 | 35 | $totalParts = count($editParts); 36 | $counter = 0; 37 | 38 | $firstField = true; 39 | 40 | ?> 41 | 48 | fetchAssoc($structureSql)) { 51 | if (in_array($structureRow['Field'], $editParts)) { 52 | echo '
'; 53 | echo '
'; 54 | echo ''; 55 | echo ''; 56 | 57 | preg_match("/^([a-z]+)(.([0-9]+).)?(.*)?$/", $structureRow['Type'], $matches); 58 | 59 | $curtype = $matches[1]; 60 | $cursizeQuotes = $matches[2]; 61 | $cursize = $matches[3]; 62 | $curextra = $matches[4]; 63 | 64 | ?> 65 | 66 | 67 | 70 | 73 | 76 | 92 | 93 | '; 101 | 102 | ?> 103 | 106 | 109 | 111 | 112 | 113 | 116 | 119 | 122 | 125 | 126 | "; 130 | echo ""; 133 | echo ""; 152 | echo ""; 153 | } 154 | 155 | ?> 156 | 157 | 160 | 165 | 166 | 167 | 172 | 173 | 174 | 177 | 178 |
68 | 69 | 71 | value="" style="width: 125px" /> 72 | 74 | 75 | 77 | 91 |
104 | 105 | 107 | " style="width: 125px" /> 108 | 110 |
114 | 115 | 117 | 118 | 120 | 121 | 123 | 124 |
"; 131 | echo __("Charset:"); 132 | echo ""; 134 | echo ""; 151 | echo "
158 | 159 | 161 | 162 | 163 | 164 |
175 | " />   176 |
179 |
180 |
181 | 182 | 191 | -------------------------------------------------------------------------------- /edituser.php: -------------------------------------------------------------------------------- 1 | 13 | Reviewed : 2016 Carlos Martín Arnillas 14 | 15 | */ 16 | 17 | include "functions.php"; 18 | 19 | loginCheck(); 20 | 21 | $conn->selectDB("mysql"); 22 | 23 | if (isset($_POST['editParts'])) { 24 | $editParts = $_POST['editParts']; 25 | 26 | $editParts = explode("; ", $editParts); 27 | 28 | $totalParts = count($editParts); 29 | $counter = 0; 30 | 31 | $firstField = true; 32 | 33 | foreach ($editParts as $part) { 34 | $part = trim($part); 35 | 36 | if ($part != "" && $part != ";") { 37 | 38 | list($user, $host) = explode("@", $part); 39 | 40 | $userSQL = $conn->query("SELECT * FROM `user` WHERE `User`='" . $user . "' AND `Host`='" . $host . "'"); 41 | $dbuserSQL = $conn->query("SELECT * FROM `db` WHERE `User`='" . $user . "' AND `Host`='" . $host . "'"); 42 | 43 | if ($conn->isResultSet($userSQL)) { 44 | 45 | $allPrivs = true; 46 | 47 | $dbShowList = array(); 48 | 49 | if ($conn->isResultSet($dbuserSQL)) { 50 | 51 | $accessLevel = "LIMITED"; 52 | 53 | while ($dbuserRow = $conn->fetchAssoc($dbuserSQL)) { 54 | $selectedPrivs = array(); 55 | 56 | $dbShowList[] = $dbuserRow['Db']; 57 | 58 | foreach ($dbuserRow as $key=>$value) { 59 | if (substr($key, -5) == "_priv" && $key != "Grant_priv" && $value == "N") { 60 | $allPrivs = false; 61 | } 62 | 63 | if ($value == "N") 64 | $selectedPrivs[$key] = $value; 65 | } 66 | 67 | if (isset($thePrivList)) { 68 | $thePrivList = array_merge($thePrivList, $selectedPrivs); 69 | } else { 70 | $thePrivList = $dbuserRow; 71 | } 72 | } 73 | } else { 74 | $accessLevel = "GLOBAL"; 75 | 76 | $userRow = $conn->fetchAssoc($userSQL); 77 | 78 | foreach ($userRow as $key=>$value) { 79 | if (substr($key, -5) == "_priv" && $key != "Grant_priv" && $value == "N") { 80 | $allPrivs = false; 81 | } 82 | } 83 | 84 | $thePrivList = $userRow; 85 | } 86 | 87 | echo '
'; 88 | echo '
'; 89 | echo ''; 90 | echo ''; 91 | 92 | ?> 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | listDatabases(); 105 | 106 | if ($conn->isResultSet($dbList)) { 107 | 108 | ?> 109 | 110 | 111 | 137 | 138 | 143 | 144 | 145 | 225 | 226 |
:
:
: 112 |
113 | 114 | 115 | 135 | 136 |
: 146 |
147 | 148 | 149 |
> 150 |
151 | 152 |
153 | 154 | 155 | 158 | 161 | 162 | 163 | 166 | 169 | 170 | 171 | 174 | 177 | 178 | 179 | 182 | 185 | 186 | 187 | 190 | 191 |
156 | 157 | 159 | 160 |
164 | 165 | 167 | 168 |
172 | 173 | 175 | 176 |
180 | 181 | 183 | 184 |
188 | 189 |
192 |
193 |
194 | 195 |
196 | 197 | 198 | 201 | 204 | 205 | 206 | 209 | 212 | 213 | 214 | 217 | 219 | 220 |
199 | 200 | 202 | 203 |
207 | 208 | 210 | 211 |
215 | 216 | 218 |
221 |
222 |
223 | 224 |
227 | 228 | 229 | 230 | 231 | 234 | 235 |
: 232 | 233 |
236 | 237 |
238 | " />   239 |
240 |
241 |
242 | 243 | 256 | -------------------------------------------------------------------------------- /home.php: -------------------------------------------------------------------------------- 1 | 13 | Reviewed : 2016 Carlos Martín Arnillas 14 | */ 15 | 16 | include "functions.php"; 17 | 18 | loginCheck(); 19 | 20 | ?> 21 | 22 | 23 | 26 | 27 | 28 | 137 | 138 | 139 | 142 | 143 | 144 | 153 | 154 | 155 | 156 | 159 | 160 | 161 | 217 | 218 | 219 | 220 | 223 | 224 | 225 | 240 | 241 | 242 | 245 | 246 | 247 | 300 |
24 |

25 |
29 | 30 | getVersion(); 33 | 34 | if (isset($_SESSION['SB_LOGIN_USER']) && $conn->getOptionValue("host")) { 35 | $message = sprintf(__("You are connected to MySQL %s with the user %s. PHP Version: %s"), $dbVersion, $_SESSION['SB_LOGIN_USER'] . "@" . $conn->getOptionValue("host"), phpversion()); 36 | } 37 | 38 | echo "

" . $message . "

"; 39 | 40 | ?> 41 | 42 | 43 | 0) { 58 | $content = strip_tags($content); 59 | 60 | list($version, $notes) = explode("\n", $content, 2); 61 | 62 | ?> 63 | 64 | 67 | 78 | 79 | 85 | 86 | 89 | 111 | 112 | 113 | 116 | 133 | 134 |
65 | : 66 | 68 | ")) { 71 | echo '' . __("A new version of SQL Buddy is available!") . ' ' . __("Download") . ' »'; 72 | } else { 73 | echo __("There are no updates available") . "."; 74 | } 75 | 76 | ?> 77 |
87 | : 88 | 90 | 0) { 93 | 94 | echo ''; 106 | 107 | } 108 | 109 | ?> 110 |
114 | : 115 | 117 | 132 |
135 | 136 |
140 |

141 |
145 | 146 |
    147 |
  • 148 |
  • 149 |
  • 150 |
151 | 152 |
157 |

158 |
162 | 163 |
164 | 165 | 166 | 169 | 172 | 173 | "; 177 | echo ""; 180 | echo ""; 203 | echo ""; 204 | } 205 | 206 | ?> 207 | 208 | 209 | 212 | 213 |
167 | : 168 | 170 | 171 |
"; 178 | echo __("Charset") . ":"; 179 | echo ""; 181 | echo ""; 202 | echo "
210 | " /> 211 |
214 |
215 | 216 |
221 |

222 |
226 | 227 |

238 | 239 |
243 |

244 |
248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 | 298 |
a
n
e
d
r
q
f
l
g
h
o
299 |
301 | -------------------------------------------------------------------------------- /images/button.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Frecuencio/sqlbuddy-php7/6614b9d3dd0321bb6588043f739a78071c3f3e93/images/button.png -------------------------------------------------------------------------------- /images/close.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Frecuencio/sqlbuddy-php7/6614b9d3dd0321bb6588043f739a78071c3f3e93/images/close.png -------------------------------------------------------------------------------- /images/closeHover.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Frecuencio/sqlbuddy-php7/6614b9d3dd0321bb6588043f739a78071c3f3e93/images/closeHover.png -------------------------------------------------------------------------------- /images/closedArrow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Frecuencio/sqlbuddy-php7/6614b9d3dd0321bb6588043f739a78071c3f3e93/images/closedArrow.png -------------------------------------------------------------------------------- /images/goto.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Frecuencio/sqlbuddy-php7/6614b9d3dd0321bb6588043f739a78071c3f3e93/images/goto.png -------------------------------------------------------------------------------- /images/info.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Frecuencio/sqlbuddy-php7/6614b9d3dd0321bb6588043f739a78071c3f3e93/images/info.png -------------------------------------------------------------------------------- /images/infoHover.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Frecuencio/sqlbuddy-php7/6614b9d3dd0321bb6588043f739a78071c3f3e93/images/infoHover.png -------------------------------------------------------------------------------- /images/initLoad.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Frecuencio/sqlbuddy-php7/6614b9d3dd0321bb6588043f739a78071c3f3e93/images/initLoad.png -------------------------------------------------------------------------------- /images/loading.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Frecuencio/sqlbuddy-php7/6614b9d3dd0321bb6588043f739a78071c3f3e93/images/loading.gif -------------------------------------------------------------------------------- /images/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Frecuencio/sqlbuddy-php7/6614b9d3dd0321bb6588043f739a78071c3f3e93/images/logo.png -------------------------------------------------------------------------------- /images/openArrow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Frecuencio/sqlbuddy-php7/6614b9d3dd0321bb6588043f739a78071c3f3e93/images/openArrow.png -------------------------------------------------------------------------------- /images/schemaHeader.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Frecuencio/sqlbuddy-php7/6614b9d3dd0321bb6588043f739a78071c3f3e93/images/schemaHeader.png -------------------------------------------------------------------------------- /images/sortasc.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Frecuencio/sqlbuddy-php7/6614b9d3dd0321bb6588043f739a78071c3f3e93/images/sortasc.gif -------------------------------------------------------------------------------- /images/sortdesc.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Frecuencio/sqlbuddy-php7/6614b9d3dd0321bb6588043f739a78071c3f3e93/images/sortdesc.gif -------------------------------------------------------------------------------- /images/transparent.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Frecuencio/sqlbuddy-php7/6614b9d3dd0321bb6588043f739a78071c3f3e93/images/transparent.png -------------------------------------------------------------------------------- /images/window-button.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Frecuencio/sqlbuddy-php7/6614b9d3dd0321bb6588043f739a78071c3f3e93/images/window-button.png -------------------------------------------------------------------------------- /images/window-center.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Frecuencio/sqlbuddy-php7/6614b9d3dd0321bb6588043f739a78071c3f3e93/images/window-center.png -------------------------------------------------------------------------------- /images/window-close.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Frecuencio/sqlbuddy-php7/6614b9d3dd0321bb6588043f739a78071c3f3e93/images/window-close.png -------------------------------------------------------------------------------- /images/window-header-center.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Frecuencio/sqlbuddy-php7/6614b9d3dd0321bb6588043f739a78071c3f3e93/images/window-header-center.png -------------------------------------------------------------------------------- /images/window-header-left.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Frecuencio/sqlbuddy-php7/6614b9d3dd0321bb6588043f739a78071c3f3e93/images/window-header-left.png -------------------------------------------------------------------------------- /images/window-header-right.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Frecuencio/sqlbuddy-php7/6614b9d3dd0321bb6588043f739a78071c3f3e93/images/window-header-right.png -------------------------------------------------------------------------------- /images/window-resize.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Frecuencio/sqlbuddy-php7/6614b9d3dd0321bb6588043f739a78071c3f3e93/images/window-resize.png -------------------------------------------------------------------------------- /images/window-shadow-bottom-left.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Frecuencio/sqlbuddy-php7/6614b9d3dd0321bb6588043f739a78071c3f3e93/images/window-shadow-bottom-left.png -------------------------------------------------------------------------------- /images/window-shadow-bottom-right.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Frecuencio/sqlbuddy-php7/6614b9d3dd0321bb6588043f739a78071c3f3e93/images/window-shadow-bottom-right.png -------------------------------------------------------------------------------- /images/window-shadow-bottom.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Frecuencio/sqlbuddy-php7/6614b9d3dd0321bb6588043f739a78071c3f3e93/images/window-shadow-bottom.png -------------------------------------------------------------------------------- /images/window-shadow-left.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Frecuencio/sqlbuddy-php7/6614b9d3dd0321bb6588043f739a78071c3f3e93/images/window-shadow-left.png -------------------------------------------------------------------------------- /images/window-shadow-right.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Frecuencio/sqlbuddy-php7/6614b9d3dd0321bb6588043f739a78071c3f3e93/images/window-shadow-right.png -------------------------------------------------------------------------------- /import.php: -------------------------------------------------------------------------------- 1 | 13 | Reviewed : 2016 Carlos Martín Arnillas 14 | 15 | */ 16 | 17 | include "functions.php"; 18 | 19 | loginCheck(); 20 | 21 | ?> 22 | 23 |
24 | 25 | 26 | 27 |

28 | 29 |
30 | 31 | 35 | 36 | 37 | 38 | 42 | 43 | 44 | 47 | 48 | 52 | 53 | 54 | 58 | 59 | 63 |
.
: 45 | 46 |
: 55 |
56 | 57 |
64 | 65 |
66 | 67 | 68 | 69 | 70 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 |
" />
84 | 85 |
86 | 87 |
88 | 89 | 90 | -------------------------------------------------------------------------------- /includes/browse.php: -------------------------------------------------------------------------------- 1 | 13 | Reviewed : 2016 Carlos Martín Arnillas 14 | 15 | */ 16 | 17 | $totalRows = 0; 18 | $insertCount = 0; 19 | $queryTime = 0; 20 | 21 | $perPage = (isset($sbconfig) && array_key_exists("RowsPerPage", $sbconfig)) ? $sbconfig['RowsPerPage'] : 100; 22 | 23 | $displayLimit = 1000; 24 | 25 | $query = trim($query); 26 | 27 | if ($query) { 28 | 29 | if (!isset($queryTable)) { 30 | $querySplit = splitQueryText($query); 31 | } else { 32 | $querySplit[] = $query; 33 | } 34 | 35 | foreach ($querySplit as $q) { 36 | $q = trim($q, "\n"); 37 | if ($q != "") { 38 | if (isset($queryTable)) { 39 | $totalRows = $conn->tableRowCount($queryTable); 40 | 41 | if ($start > $totalRows) { 42 | $start = 0; 43 | } 44 | 45 | $q = "$q $sort LIMIT $start, $perPage"; 46 | } 47 | 48 | $queryStartTime = microtime_float(); 49 | $dataSql = $conn->query($q) or ($dbError[] = $conn->error()); 50 | $queryFinishTime = microtime_float(); 51 | $queryTime += round($queryFinishTime - $queryStartTime, 4); 52 | 53 | if ($conn->affectedRows($dataSql)) { 54 | $insertCount += (int)($conn->affectedRows($dataSql)); 55 | } 56 | } 57 | } 58 | 59 | if (!isset($queryTable)) { 60 | $totalRows = (int)($conn->rowCount($dataSql)); 61 | } 62 | 63 | } 64 | 65 | //for the browse tab 66 | if (isset($queryTable)) { 67 | $structureSql = $conn->describeTable($queryTable); 68 | 69 | if ($conn->isResultSet($structureSql)) { 70 | while ($structureRow = $conn->fetchAssoc($structureSql)) { 71 | $explosion = explode("(", $structureRow['Type'], 2); 72 | 73 | $tableTypes[] = $explosion[0]; 74 | 75 | if ($structureRow['Key'] == "PRI") { 76 | $primaryKeys[] = $structureRow['Field']; 77 | } 78 | } 79 | } 80 | } 81 | 82 | echo '
'; 83 | 84 | if (isset($dbError)) { 85 | echo '
' . __("The following errors were reported") . ':'; 86 | foreach ($dbError as $error) { 87 | echo $error . "
"; 88 | } 89 | echo '
'; 90 | } else { 91 | 92 | if (isset($totalRows) && $totalRows > 0) { 93 | 94 | if (isset($queryTable)) { 95 | 96 | echo ''; 97 | echo ''; 98 | echo ''; 112 | 113 | echo ''; 162 | echo ''; 163 | echo '
'; 99 | 100 | if (isset($primaryKeys) && count($primaryKeys)) { 101 | 102 | echo __("Select") . ':  ' . __("All") . '  ' . __("None") . ''; 103 | echo '     ' . __("With selected") . ':  ' . __("Edit") . '  ' . __("Delete") . ''; 104 | 105 | echo '       ' . __("Refresh") . ''; 106 | 107 | } else { 108 | echo '[' . __("No primary key defined") . ']'; 109 | } 110 | 111 | echo ''; 114 | 115 | $totalPages = ceil($totalRows / $perPage); 116 | $currentPage = floor($start / $perPage) + 1; 117 | 118 | if ($currentPage > 1) { 119 | echo '' . __("First") . ''; 120 | echo '' . __("Prev") . ''; 121 | } 122 | 123 | echo ''; 124 | 125 | if ($currentPage == 1) { 126 | $startPage = 1; 127 | $finishPage = 3; 128 | 129 | if ($finishPage > $totalPages) 130 | $finishPage = $totalPages; 131 | 132 | } else if ($currentPage == $totalPages) { 133 | $startPage = $totalPages - 2; 134 | $finishPage = $totalPages; 135 | 136 | if ($startPage < 1) 137 | $startPage = 1; 138 | } else { 139 | $startPage = $currentPage - 1; 140 | $finishPage = $currentPage + 1; 141 | } 142 | 143 | if ($startPage != $finishPage) { 144 | for ($bnav=$startPage; $bnav<=$finishPage; $bnav++) { 145 | echo '' . number_format($bnav) . ''; 151 | } 152 | } 153 | 154 | echo ''; 155 | 156 | if ($currentPage < $totalPages) { 157 | echo '' . __("Next") . ''; 158 | echo '' . __("Last") . ''; 159 | } 160 | 161 | echo '
'; 164 | 165 | } else { 166 | echo ''; 167 | echo ''; 168 | echo ''; 176 | echo ''; 177 | echo '
'; 169 | 170 | printf(__p("Your query returned %d result.", "Your query returned %d results.", $totalRows), $totalRows); 171 | echo " " . sprintf(__("(%.4f seconds)"), $queryTime); 172 | 173 | if ($totalRows > $displayLimit) 174 | echo ' (' . sprintf(__("Note: To avoid crashing your browser, only the first %d results have been displayed"), $displayLimit) . '.)'; 175 | echo '
'; 178 | } 179 | 180 | echo '
'; 181 | 182 | if (isset($primaryKeys) && count($primaryKeys)) { 183 | echo '
 
'; 184 | } 185 | 186 | echo '
'; 192 | 193 | echo '
'; 194 | echo ''; 195 | echo ''; 196 | 197 | if ($conn->isResultSet($dataSql)) { 198 | $dataRow = $conn->fetchAssoc($dataSql); 199 | $g = 0; 200 | $numFields = 0; 201 | 202 | foreach ($dataRow as $key=>$value) { 203 | 204 | if ((isset($sortKey) && $sortKey == $key) && (isset($sortDir) && $sortDir == "ASC")) { 205 | $outputDir = "DESC"; 206 | } elseif (isset($sortKey) && $sortKey == $key) { 207 | $outputDir = "ASC"; 208 | } elseif (isset($sortDir) && $sortDir) { 209 | $outputDir = $sortDir; 210 | } else { 211 | $outputDir = "ASC"; 212 | } 213 | echo ''; 245 | echo ''; 246 | $numFields++; 247 | } 248 | echo ''; 249 | echo ''; 250 | echo '
'; 232 | 233 | if ((isset($sortKey) && $sortKey == $key) && (isset($sortDir) && $sortDir == "DESC")) { 234 | echo '
' . $key . '
'; 235 | } elseif ((isset($sortKey) && $sortKey == $key) && (isset($sortDir) && $sortDir == "ASC")) { 236 | echo '
' . $key . '
'; 237 | } else { 238 | echo $key; 239 | } 240 | 241 | $fieldList[] = $key; 242 | 243 | echo '
'; 244 | echo '
 
'; 251 | 252 | } 253 | 254 | echo '
'; 255 | echo '
'; 256 | 257 | $dataSql = $conn->query($q); 258 | 259 | $queryBuilder = ""; 260 | 261 | if (isset($primaryKeys) && count($primaryKeys) > 0) { 262 | 263 | echo '
'; 264 | 265 | $m = 0; 266 | 267 | while (($dataRow = $conn->fetchAssoc($dataSql)) && ($m < $displayLimit)) { 268 | 269 | $queryBuilder = "WHERE "; 270 | foreach ($primaryKeys as $primary) { 271 | $queryBuilder .= "`" . $primary . "`='" . $dataRow[$primary] . "' AND "; 272 | } 273 | $queryBuilder = substr($queryBuilder, 0, -5); 274 | 275 | $queryBuilder .= " LIMIT 1"; 276 | 277 | echo '
'; 285 | echo '
'; 286 | echo '
'; 287 | echo '
'; 288 | 289 | $m++; 290 | } 291 | 292 | echo '
'; 293 | 294 | $dataSql = $conn->query($q); 295 | 296 | } 297 | 298 | if (isset($primaryKeys) && count($primaryKeys)) 299 | echo '
'; 300 | else 301 | echo '
'; 302 | 303 | $m = 0; 304 | 305 | while (($dataRow = $conn->fetchArray($dataSql)) && ($m < $displayLimit)) { 306 | 307 | echo ''; 315 | echo ''; 316 | echo ''; 344 | echo ''; 345 | echo '
'; 317 | 318 | echo ''; 319 | echo ''; 320 | 321 | for ($i=0; $i<$numFields; $i++) { 322 | echo ''; 340 | } 341 | echo ''; 342 | echo '
'; 330 | 331 | if (isset($tableTypes) && in_array($tableTypes[$i], $binaryDTs)) { 332 | echo '(' . __("binary data") . ')'; 333 | } else if (is_numeric($dataRow[$i]) && stristr($fieldList[$i], "Date") !== false && strlen($dataRow[$i]) > 7 && strlen($dataRow[$i]) < 14) { 334 | echo '' . formatForOutput($dataRow[$i]) . ''; 335 | } else { 336 | echo formatForOutput($dataRow[$i]); 337 | } 338 | 339 | echo '
'; 343 | echo '
'; 346 | 347 | $m++; 348 | } 349 | echo '
'; 350 | echo '
'; 351 | 352 | ?> 353 | 354 | 357 | 358 | ' . sprintf(__("Your query affected %d rows."), $insertCount) . '
'; 362 | 363 | if (isset($queryTable) && $queryTable) { 364 | ?> 365 | 366 | 371 | 372 | ' . __("Your query did not return any results.") . " " . sprintf(__("(%.4f seconds)"), $queryTime) . '
'; 375 | } 376 | } 377 | } 378 | 379 | echo ''; 380 | 381 | ?> 382 | -------------------------------------------------------------------------------- /includes/class/GetTextReader.php: -------------------------------------------------------------------------------- 1 | 13 | 14 | */ 15 | 16 | class GetTextReader { 17 | 18 | var $translationIndex = array(); 19 | var $basePath = "locale/"; 20 | 21 | function __construct($inputFile) { 22 | 23 | $msgId = ""; 24 | $msgIdPlural = ""; 25 | $msgStr = ""; 26 | $msgStrPlural = ""; 27 | 28 | $readFile = $this->basePath . $inputFile; 29 | 30 | if (file_exists($readFile)) { 31 | $handle = fopen($readFile, "r"); 32 | if ($handle) { 33 | while (!feof($handle)) 34 | { 35 | $lines[] = trim(fgets($handle, 4096)); 36 | } 37 | fclose($handle); 38 | } 39 | 40 | foreach ($lines as $line) { 41 | if (substr($line, 0, 6) == "msgid:") { 42 | $msgId = substr($line, 8, -1); 43 | $msgStr = ""; 44 | } else if (substr($line, 0, 13) == "msgid_plural:") { 45 | $msgIdPlural = substr($line, 15, -1); 46 | } else if (substr($line, 0, 7) == "msgstr:") { 47 | $msgStr = substr($line, 9, -1); 48 | } else if (substr($line, 0, 10) == "msgstr[0]:") { 49 | $msgStr = substr($line, 12, -1); 50 | } else if (substr($line, 0, 10) == "msgstr[1]:") { 51 | $msgStrPlural = substr($line, 12, -1); 52 | } 53 | 54 | if ($msgId && $msgStr) { 55 | $this->translationIndex[$msgId] = $msgStr; 56 | if ($msgIdPlural) 57 | $this->translationIndex[$msgIdPlural] = $msgStrPlural; 58 | 59 | $msgId = ""; 60 | $msgIdPlural = ""; 61 | $msgStr = ""; 62 | $msgStrPlural = ""; 63 | } 64 | } 65 | } 66 | } 67 | 68 | function getTranslation($lookup) { 69 | if (array_key_exists($lookup, $this->translationIndex)) { 70 | return $this->translationIndex[$lookup]; 71 | } else { 72 | return $lookup; 73 | } 74 | } 75 | 76 | } 77 | 78 | ?> -------------------------------------------------------------------------------- /includes/class/Sql.php: -------------------------------------------------------------------------------- 1 | 13 | Reviewed : 2016 Carlos Martín Arnillas 14 | */ 15 | 16 | class SQL { 17 | 18 | var $version = ""; 19 | var $conn = ""; 20 | var $options = ""; 21 | var $errorMessage = ""; 22 | var $db = ""; 23 | 24 | function __construct($connString, $user = "", $pass = "") { 25 | list($this->adapter, $options) = explode(":", $connString, 2); 26 | 27 | $optionsList = explode(";", $options); 28 | 29 | foreach ($optionsList as $option) { 30 | list($a, $b) = explode("=", $option); 31 | $opt[$a] = $b; 32 | } 33 | 34 | $this->options = $opt; 35 | $database = (array_key_exists("database", $opt)) ? $opt['database'] : ""; 36 | 37 | $host = (array_key_exists("host", $opt)) ? $opt['host'] : ""; 38 | $this->conn = @mysqli_connect($host, $user, $pass); 39 | 40 | $this->query("SET NAMES 'utf8'"); 41 | $_SESSION['MYSQL_VERSION'] = mysqli_get_server_version($this->conn); 42 | 43 | if ($this->conn && $database) { 44 | $this->db = $database; 45 | } 46 | } 47 | 48 | function isConnected() { 49 | return ($this->conn !== false); 50 | } 51 | 52 | function disconnect() { 53 | if ($this->conn) { 54 | mysqli_close($this->conn); 55 | $this->conn = null; 56 | } 57 | } 58 | 59 | 60 | function getOptionValue($optKey) { 61 | if (array_key_exists($optKey, $this->options)) { 62 | return $this->options[$optKey]; 63 | } else { 64 | return false; 65 | } 66 | } 67 | 68 | function selectDB($db) { 69 | if ($this->conn) { 70 | $this->db = $db; 71 | return (mysqli_select_db($this->conn,$db)); 72 | } 73 | return false; 74 | } 75 | 76 | function query($queryText) { 77 | if ($this->conn) { 78 | $queryResult = @mysqli_query($this->conn, $queryText); 79 | 80 | if (!$queryResult) { 81 | $this->errorMessage = mysqli_error($this->conn); 82 | } 83 | 84 | return $queryResult; 85 | } 86 | return false; 87 | } 88 | 89 | function rowCount($resultSet) { 90 | if (!$resultSet) { 91 | return false; 92 | } 93 | 94 | if ($this->conn) { 95 | return @mysqli_num_rows($resultSet); 96 | } 97 | return false; 98 | } 99 | 100 | function isResultSet($resultSet) { 101 | if ($this->conn) { 102 | return ($this->rowCount($resultSet) > 0); 103 | } 104 | return false; 105 | } 106 | 107 | function fetchArray($resultSet) { 108 | if (!$resultSet) { 109 | return false; 110 | } 111 | 112 | if ($this->conn) { 113 | return mysqli_fetch_row($resultSet); 114 | } 115 | return false; 116 | } 117 | 118 | function fetchAssoc($resultSet) { 119 | if (!$resultSet) { 120 | return false; 121 | } 122 | 123 | if ($this->conn) { 124 | return mysqli_fetch_assoc($resultSet); 125 | } 126 | return false; 127 | } 128 | 129 | function affectedRows($resultSet) { 130 | if (!$resultSet) { 131 | return false; 132 | } 133 | 134 | if ($this->conn) { 135 | return @mysqli_affected_rows($resultSet); 136 | } 137 | return false; 138 | } 139 | 140 | function result($resultSet, $targetRow, $targetColumn = "") { 141 | if (!$resultSet) { 142 | return false; 143 | } 144 | if ($this->conn) { 145 | return $this->mysqli_result($resultSet, $targetRow, $targetColumn); 146 | return $row[$field]; 147 | } 148 | return false; 149 | } 150 | 151 | function listDatabases() { 152 | if ($this->conn) { 153 | return $this->query("SHOW DATABASES"); 154 | } 155 | } 156 | 157 | function listTables() { 158 | if ($this->conn) { 159 | return $this->query("SHOW TABLES"); 160 | } 161 | } 162 | 163 | function hasCharsetSupport() 164 | { 165 | return $this->conn && version_compare($this->getVersion(), "4.1", ">"); 166 | } 167 | 168 | function listCharset() { 169 | if ($this->conn) { 170 | return $this->query("SHOW CHARACTER SET"); 171 | } 172 | return ''; 173 | } 174 | 175 | function listCollation() { 176 | if ($this->conn) { 177 | return $this->query("SHOW COLLATION"); 178 | } 179 | return ''; 180 | } 181 | 182 | function listEngines() { 183 | if ($this->conn) { 184 | return $this->query("SHOW ENGINES"); 185 | } 186 | return ''; 187 | } 188 | 189 | function insertId() { 190 | if ($this->conn) { 191 | return @mysqli_insert_id($this->conn); 192 | } 193 | return ''; 194 | } 195 | 196 | function escapeString($toEscape) { 197 | if ($this->conn) { 198 | return mysqli_real_escape_string($this->conn ,$toEscape); 199 | } 200 | return ''; 201 | } 202 | 203 | function getVersion() { 204 | if ($this->conn) { 205 | // cache 206 | if ($this->version) { 207 | return $this->version; 208 | } 209 | $verSql = mysqli_get_server_info($this->conn); 210 | $version = explode("-", $verSql); 211 | $this->version = $version[0]; 212 | return $this->version; 213 | } 214 | return ''; 215 | } 216 | 217 | // returns the number of rows in a table 218 | function tableRowCount($table) { 219 | if ($this->conn) { 220 | $countSql = $this->query("SELECT COUNT(*) AS `RowCount` FROM `" . $table . "`"); 221 | $count = (int)($this->result($countSql, 0, "RowCount")); 222 | return $count; 223 | } 224 | return ''; 225 | } 226 | 227 | // gets column info for a table 228 | function describeTable($table) { 229 | if ($this->conn) { 230 | return $this->query("DESCRIBE `" . $table . "`"); 231 | } 232 | return ''; 233 | } 234 | 235 | /* 236 | Return names, row counts etc for every database, table and view in a JSON string 237 | */ 238 | function getMetadata() { 239 | $output = ''; 240 | if ($this->conn) { 241 | if (version_compare($this->getVersion(), "5.0.0", ">=")) { 242 | $this->selectDB("information_schema"); 243 | $schemaSql = $this->query("SELECT `SCHEMA_NAME` FROM `SCHEMATA` ORDER BY `SCHEMA_NAME`"); 244 | if ($this->rowCount($schemaSql)) { 245 | while ($schema = $this->fetchAssoc($schemaSql)) { 246 | $output .= '{"name": "' . $schema['SCHEMA_NAME'] . '"'; 247 | // other interesting columns: TABLE_TYPE, ENGINE, TABLE_COLUMN and many more 248 | $tableSql = $this->query("SELECT `TABLE_NAME`, `TABLE_ROWS` FROM `TABLES` WHERE `TABLE_SCHEMA`='" . $schema['SCHEMA_NAME'] . "' ORDER BY `TABLE_NAME`"); 249 | if ($this->rowCount($tableSql)) { 250 | $output .= ',"items": ['; 251 | while ($table = $this->fetchAssoc($tableSql)) { 252 | 253 | if ($schema['SCHEMA_NAME'] == "information_schema") { 254 | $countSql = $this->query("SELECT COUNT(*) AS `RowCount` FROM `" . $table['TABLE_NAME'] . "`"); 255 | $rowCount = (int)($this->result($countSql, 0, "RowCount")); 256 | } else { 257 | $rowCount = (int)($table['TABLE_ROWS']); 258 | } 259 | 260 | $output .= '{"name":"' . $table['TABLE_NAME'] . '","rowcount":' . $rowCount . '},'; 261 | } 262 | 263 | if (substr($output, -1) == ",") 264 | $output = substr($output, 0, -1); 265 | 266 | $output .= ']'; 267 | } 268 | $output .= '},'; 269 | } 270 | $output = substr($output, 0, -1); 271 | } 272 | } else { 273 | $schemaSql = $this->listDatabases(); 274 | 275 | if ($this->rowCount($schemaSql)) { 276 | while ($schema = $this->fetchArray($schemaSql)) { 277 | $output .= '{"name": "' . $schema[0] . '"'; 278 | 279 | $this->selectDB($schema[0]); 280 | $tableSql = $this->listTables(); 281 | 282 | if ($this->rowCount($tableSql)) { 283 | $output .= ',"items": ['; 284 | while ($table = $this->fetchArray($tableSql)) { 285 | $countSql = $this->query("SELECT COUNT(*) AS `RowCount` FROM `" . $table[0] . "`"); 286 | $rowCount = (int)($this->result($countSql, 0, "RowCount")); 287 | $output .= '{"name":"' . $table[0] . '","rowcount":' . $rowCount . '},'; 288 | } 289 | 290 | if (substr($output, -1) == ",") 291 | $output = substr($output, 0, -1); 292 | 293 | $output .= ']'; 294 | } 295 | $output .= '},'; 296 | } 297 | $output = substr($output, 0, -1); 298 | } 299 | } 300 | } 301 | return $output; 302 | } 303 | 304 | function error() { 305 | return $this->errorMessage; 306 | } 307 | 308 | protected function mysqli_result($res,$row=0,$col=0){ 309 | $numrows = mysqli_num_rows($res); 310 | if ($numrows && $row <= ($numrows-1) && $row >=0){ 311 | mysqli_data_seek($res,$row); 312 | $resrow = (is_numeric($col)) ? mysqli_fetch_row($res) : mysqli_fetch_assoc($res); 313 | if (isset($resrow[$col])){ 314 | return $resrow[$col]; 315 | } 316 | } 317 | return false; 318 | } 319 | 320 | } 321 | -------------------------------------------------------------------------------- /includes/types.php: -------------------------------------------------------------------------------- 1 | 13 | Reviewed : 2016 Carlos Martín Arnillas 14 | 15 | */ 16 | 17 | $typeList[] = "varchar"; 18 | $typeList[] = "char"; 19 | $typeList[] = "text"; 20 | $typeList[] = "tinytext"; 21 | $typeList[] = "mediumtext"; 22 | $typeList[] = "longtext"; 23 | $typeList[] = "tinyint"; 24 | $typeList[] = "smallint"; 25 | $typeList[] = "mediumint"; 26 | $typeList[] = "int"; 27 | $typeList[] = "bigint"; 28 | $typeList[] = "real"; 29 | $typeList[] = "double"; 30 | $typeList[] = "float"; 31 | $typeList[] = "decimal"; 32 | $typeList[] = "numeric"; 33 | $typeList[] = "date"; 34 | $typeList[] = "time"; 35 | $typeList[] = "datetime"; 36 | $typeList[] = "timestamp"; 37 | $typeList[] = "tinyblob"; 38 | $typeList[] = "blob"; 39 | $typeList[] = "mediumblob"; 40 | $typeList[] = "longblob"; 41 | $typeList[] = "binary"; 42 | $typeList[] = "varbinary"; 43 | $typeList[] = "bit"; 44 | $typeList[] = "enum"; 45 | $typeList[] = "set"; 46 | 47 | if(isset($_SESSION['MYSQL_VERSION']) && $_SESSION['MYSQL_VERSION'] >= 5.7) { 48 | $typeList[] = "json"; 49 | 50 | $typeList[] = "geometry"; 51 | $typeList[] = "point"; 52 | $typeList[] = "linestring"; 53 | $typeList[] = "polygon"; 54 | $typeList[] = "multipoint"; 55 | $typeList[] = "multilinestring"; 56 | $typeList[] = "multipolygon"; 57 | $typeList[] = "geometrycollection"; 58 | } 59 | 60 | $textDTs[] = "text"; 61 | $textDTs[] = "mediumtext"; 62 | $textDTs[] = "longtext"; 63 | 64 | $numericDTs[] = "tinyint"; 65 | $numericDTs[] = "smallint"; 66 | $numericDTs[] = "mediumint"; 67 | $numericDTs[] = "int"; 68 | $numericDTs[] = "bigint"; 69 | $numericDTs[] = "real"; 70 | $numericDTs[] = "double"; 71 | $numericDTs[] = "float"; 72 | $numericDTs[] = "decimal"; 73 | $numericDTs[] = "numeric"; 74 | 75 | $binaryDTs[] = "tinyblob"; 76 | $binaryDTs[] = "blob"; 77 | $binaryDTs[] = "mediumblob"; 78 | $binaryDTs[] = "longblob"; 79 | $binaryDTs[] = "binary"; 80 | $binaryDTs[] = "varbinary"; 81 | 82 | ?> 83 | -------------------------------------------------------------------------------- /index.php: -------------------------------------------------------------------------------- 1 | 13 | Reviewed : 2016 Carlos Martín Arnillas 14 | 15 | */ 16 | 17 | include "functions.php"; 18 | 19 | loginCheck(false); 20 | 21 | outputPage(); 22 | 23 | ?> 24 | -------------------------------------------------------------------------------- /insert.php: -------------------------------------------------------------------------------- 1 | 13 | Reviewed : 2016 Carlos Martín Arnillas 14 | 15 | */ 16 | 17 | include "functions.php"; 18 | 19 | loginCheck(); 20 | 21 | requireDatabaseAndTableBeDefined(); 22 | 23 | if (isset($db)) { 24 | $conn->selectDB($db); 25 | } 26 | 27 | if (isset($table)){ 28 | $structureSql = $conn->describeTable($table); 29 | } 30 | 31 | if ($conn->isResultSet($structureSql)) { 32 | while ($structureRow = $conn->fetchAssoc($structureSql)) { 33 | $types[$structureRow['Field']] = $structureRow['Type']; 34 | } 35 | $structureSql = $conn->describeTable($table); 36 | } 37 | 38 | if ($conn->isResultSet($structureSql) || sizeof($structureSql) > 0) { 39 | 40 | if ($_POST) { 41 | 42 | $insertFields = ""; 43 | $insertValues = ""; 44 | 45 | foreach ($_POST as $key=>$value) { 46 | 47 | $insertFields .= "`" . $key . "`,"; 48 | 49 | if (is_array($value)) { 50 | $value = implode(",", $value); 51 | } 52 | 53 | if (isset($types) && substr($value, 0, 2) == "0x" && isset($binaryDTs) && in_array($types[$key], $binaryDTs)) { 54 | $insertValues .= $conn->escapeString(urldecode($value)) . ","; 55 | } else { 56 | $insertValues .= "'" . $conn->escapeString(urldecode($value)) . "',"; 57 | } 58 | 59 | } 60 | 61 | $insertFields = substr($insertFields, 0, -1); 62 | $insertValues = substr($insertValues, 0, -1); 63 | 64 | $insertQuery = "INSERT INTO `$table` (" . $insertFields . ") VALUES (" . $insertValues . ")"; 65 | 66 | $conn->query($insertQuery) or ($dbError = $conn->error()); 67 | 68 | $insertId = $conn->insertId(); 69 | 70 | if (isset($dbError)) { 71 | echo '
' . $dbError . '
'; 72 | } else { 73 | echo '
'; 74 | echo __("Your data has been inserted into the database."); 75 | if ($insertId) 76 | echo ' (Id: ' . $insertId . ')'; 77 | echo '
'; 78 | 79 | ?> 80 | 81 | 87 | 88 | 94 | 95 |
96 | 97 | isResultSet($structureSql)) { 101 | while ($structureRow = $conn->fetchAssoc($structureSql)) { 102 | 103 | preg_match("/^([a-z]+)(.([0-9]+).)?(.*)?$/", $structureRow['Type'], $matches); 104 | 105 | $curtype = $matches[1]; 106 | $cursizeQuotes = $matches[2]; 107 | $cursize = $matches[3]; 108 | $curextra = $matches[4]; 109 | 110 | echo ''; 111 | echo ''; 116 | echo ""; 117 | echo ""; 118 | echo ' 158 | 159 | 160 | 164 | 165 | 168 | 169 |
'; 112 | if ($structureRow['Key'] == 'PRI') echo ''; 113 | echo $structureRow['Field']; 114 | if ($structureRow['Key'] == 'PRI') echo ''; 115 | echo " " . $curtype . $cursizeQuotes . ' ' . $structureRow['Extra'] . '
'; 119 | if ($structureRow['Type'] == "text") { 120 | echo ''; 124 | } 125 | elseif (substr($structureRow['Type'], 0, 4) == "enum") { 126 | $trimmed = substr($structureRow['Type'], 6, -2); 127 | $listOptions = explode("','", $trimmed); 128 | echo ''; 134 | } 135 | elseif (substr($structureRow['Type'], 0, 3) == "set") { 136 | $trimmed = substr($structureRow['Type'], 5, -2); 137 | $listOptions = explode("','", $trimmed); 138 | foreach ($listOptions as $option) { 139 | $id = $option . rand(1, 1000); 140 | echo '
'; 141 | } 142 | } else { 143 | echo ''; 153 | } 154 | 155 | ?> 156 | 157 |
166 | " /> 167 |
170 |
171 | 172 | 176 | 181 | 186 | 187 |
188 |

189 |

190 |
191 | 192 | 196 | -------------------------------------------------------------------------------- /js/movement.js: -------------------------------------------------------------------------------- 1 | var mouseX = -1; 2 | var mouseY = -1; 3 | var lastWidth = -1; 4 | var lastHeight = -1; 5 | var lastLeft = -1; 6 | var lastTop = -1; 7 | var activeContent; 8 | var compX = 0; 9 | var compY = 0; 10 | var activeColumnId = -1; 11 | var activeColumn; 12 | var styleNodeKeys = []; 13 | var styleNodes = []; 14 | 15 | function startResize(e) { 16 | var event = new Event(e); 17 | 18 | activeWindow = event.target; 19 | while (activeWindow != null && activeWindow.className.indexOf("fulltextwin") == -1) { 20 | activeWindow = activeWindow.parentNode; 21 | } 22 | 23 | activeContent = $E(".fulltextcontent", activeWindow); 24 | 25 | lastWidth = parseInt(activeWindow.offsetWidth); 26 | lastHeight = parseInt(activeContent.offsetHeight); 27 | mouseX = event.page.x; 28 | mouseY = event.page.y; 29 | 30 | activeContent.style.height = lastHeight + "px"; 31 | activeContent.style.maxHeight = ''; 32 | 33 | window.addEvent("mousemove", doResize); 34 | window.addEvent("mouseup", endResize); 35 | 36 | return false; 37 | } 38 | 39 | function doResize(e) { 40 | if (activeWindow) { 41 | var event = new Event(e); 42 | 43 | var diffX = event.page.x - mouseX; 44 | var diffY = event.page.y - mouseY; 45 | 46 | if (compX > 0 && compX > diffX) { 47 | compX -= diffX; 48 | diffX = 0; 49 | } else if (compX > 0) { 50 | diffX -= compX; 51 | compX = 0; 52 | } 53 | 54 | if (compY > 0 && compY > diffY) { 55 | compY -= diffY; 56 | diffY = 0; 57 | } else if (compY > 0) { 58 | diffY -= compY; 59 | compY = 0; 60 | } 61 | 62 | lastWidth = lastWidth + diffX; 63 | lastHeight = lastHeight + diffY; 64 | 65 | if (lastWidth < 175) { 66 | compX += 175 - lastWidth; 67 | lastWidth = 175; 68 | } 69 | 70 | if (lastHeight < 100) { 71 | compY += 100 - lastHeight; 72 | lastHeight = 100; 73 | } 74 | 75 | mouseX = event.page.x; 76 | mouseY = event.page.y; 77 | 78 | activeWindow.style.width = lastWidth + "px"; 79 | activeContent.style.height = lastHeight + "px"; 80 | } 81 | } 82 | 83 | function endResize() { 84 | activeWindow = null; 85 | activeContent = null; 86 | compX = 0; 87 | compY = 0; 88 | window.removeEvent("mousemove", doResize); 89 | window.removeEvent("mouseup", endResize); 90 | } 91 | 92 | function startDrag(e) { 93 | var event = new Event(e); 94 | 95 | activeWindow = event.target; 96 | while (activeWindow != null && activeWindow.className.indexOf("fulltextwin") == -1) { 97 | activeWindow = activeWindow.parentNode; 98 | } 99 | 100 | lastLeft = activeWindow.style.left; 101 | lastLeft = parseInt(lastLeft.substring(0, lastLeft.length - 2)); 102 | lastTop = activeWindow.style.top; 103 | lastTop = parseInt(lastTop.substring(0, lastTop.length - 2)); 104 | mouseX = event.page.x; 105 | mouseY = event.page.y; 106 | 107 | window.addEvent("mousemove", doDrag); 108 | window.addEvent("mouseup", endDrag); 109 | 110 | return false; 111 | } 112 | 113 | function doDrag(e) { 114 | if (activeWindow) { 115 | var event = new Event(e); 116 | 117 | var diffX = event.page.x - mouseX; 118 | var diffY = event.page.y - mouseY; 119 | 120 | lastLeft = lastLeft + diffX; 121 | lastTop = lastTop + diffY; 122 | mouseX = event.page.x; 123 | mouseY = event.page.y; 124 | 125 | activeWindow.style.left = lastLeft + "px"; 126 | activeWindow.style.top = lastTop + "px"; 127 | } 128 | } 129 | 130 | function endDrag() { 131 | activeWindow = null; 132 | window.removeEvent("mousemove", doDrag); 133 | window.removeEvent("mouseup", endDrag); 134 | } 135 | 136 | function startColumnResize(e) { 137 | var event = new Event(e); 138 | 139 | activeColumn = $(event.target.offsetParent.previousSibling.firstChild); 140 | 141 | activeColumnId = parseInt(activeColumn.getProperty("column")); 142 | 143 | lastWidth = parseInt(activeColumn.clientWidth) - 11; // -11 to account for padding 144 | mouseX = event.page.x; 145 | 146 | document.body.style.cursor = "ew-resize"; 147 | 148 | window.addEvent("mousemove", columnResize); 149 | window.addEvent("mouseup", endColumnResize); 150 | 151 | return false; 152 | } 153 | 154 | function columnResize(e) { 155 | if (activeColumn) { 156 | var event = new Event(e); 157 | 158 | var diff = (event.page.x - mouseX); 159 | 160 | lastWidth = (lastWidth + diff); 161 | mouseX = event.page.x; 162 | 163 | var removeLater = -1; 164 | var keyName = 'pane' + sb.topTab + '_' + activeColumnId; 165 | 166 | for (var i=0; i= 0) { 174 | styleNodes.splice(removeLater, 1); 175 | styleNodeKeys.splice(removeLater, 1); 176 | } 177 | 178 | var newNode = new Element("style"); 179 | newNode.setAttribute("type", "text/css"); 180 | 181 | newNode.appendText("#pane" + sb.topTab + " .column" + activeColumnId + " { width: " + lastWidth + "px !important }"); 182 | document.getElementsByTagName("head")[0].appendChild(newNode); 183 | 184 | styleNodes.push(newNode); 185 | styleNodeKeys.push(keyName); 186 | } 187 | } 188 | 189 | function endColumnResize() { 190 | document.body.style.cursor = ""; 191 | activeColumn = null; 192 | window.removeEvent("mousemove", columnResize); 193 | window.removeEvent("mouseup", endColumnResize); 194 | } 195 | 196 | function clearColumnSizes() { 197 | if (styleNodes.length > 0) { 198 | for (var i=0; i 13 | Reviewed : 2016 Carlos Martín Arnillas 14 | 15 | */ 16 | 17 | include "functions.php"; 18 | 19 | $adapter = (isset($sbconfig['DefaultAdapter'])) ? $sbconfig['DefaultAdapter'] : "mysql"; 20 | $host = (isset($sbconfig['DefaultHost'])) ? $sbconfig['DefaultHost'] : "localhost"; 21 | $user = (isset($sbconfig['DefaultUser'])) ? $sbconfig['DefaultUser'] : "root"; 22 | $pass = (isset($sbconfig['DefaultPass'])) ? $sbconfig['DefaultPass'] : ""; 23 | 24 | // SQLite only 25 | $database = (isset($sbconfig['DefaultDatabase'])) ? $sbconfig['DefaultDatabase'] : ""; 26 | 27 | if ($_POST) { 28 | if (isset($_POST['ADAPTER'])) 29 | $adapter = $_POST['ADAPTER']; 30 | 31 | if (isset($_POST['HOST'])) 32 | $host = $_POST['HOST']; 33 | 34 | if (isset($_POST['USER'])) 35 | $user = $_POST['USER']; 36 | 37 | if (isset($_POST['PASS'])) 38 | $pass = $_POST['PASS']; 39 | 40 | if (isset($_POST['DATABASE'])) 41 | $database = $_POST['DATABASE']; 42 | } 43 | 44 | if (!in_array($adapter, $adapterList)) { 45 | $adapter = "mysql"; 46 | } 47 | 48 | if (($adapter != "sqlite" && $host && $user && ($pass || $_POST)) || ($adapter == "sqlite" && $database)) { 49 | 50 | if ($adapter == "sqlite") { 51 | $connString = "sqlite:database=$database"; 52 | $connCheck = new SQL($connString); 53 | $user = ""; 54 | $pass = ""; 55 | } else { 56 | $connString = "$adapter:host=$host"; 57 | $connCheck = new SQL($connString, $user, $pass); 58 | } 59 | 60 | if ($connCheck->isConnected()) { 61 | $_SESSION['SB_LOGIN'] = true; 62 | $_SESSION['SB_LOGIN_STRING'] = $connString; 63 | $_SESSION['SB_LOGIN_USER'] = $user; 64 | $_SESSION['SB_LOGIN_PASS'] = $pass; 65 | 66 | $path = $_SERVER["SCRIPT_NAME"]; 67 | $pathSplit = explode("/", $path); 68 | 69 | $redirect = ""; 70 | 71 | for ($i=0; $i 95 | 96 | 97 | 98 | SQL Buddy 99 | 100 | " /> 101 | " /> 102 | " media="print" /> 103 | " /> 104 | 107 | 108 | 109 | 110 | 111 | 112 |
113 |
114 |
115 |
116 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 |

140 | 145 | 146 | 147 | 148 | 149 | '; 152 | } 153 | if (isset($_GET['timeout'])) { 154 | echo ''; 155 | } 156 | 157 | if (sizeof($adapterList) > 1) { 158 | 159 | ?> 160 | 161 | 162 | 181 | 182 | 187 |

' . $error . '
' . __("Your session has timed out. Please login again.") . '
163 | 180 |
188 | > 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | > 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 |
" />
214 | 219 |
220 |
221 |
222 |
223 | 267 | 268 | 269 | -------------------------------------------------------------------------------- /logout.php: -------------------------------------------------------------------------------- 1 | 13 | Reviewed : 2016 Carlos Martín Arnillas 14 | 15 | */ 16 | 17 | if (!session_id()) 18 | session_start(); 19 | 20 | if (isset($_SESSION['SB_LOGIN'])) { 21 | $_SESSION['SB_LOGIN'] = null; 22 | unset($GLOBALS['_SESSION']['SB_LOGIN']); 23 | } 24 | 25 | if (isset($_SESSION['SB_LOGIN_STRING'])) { 26 | $_SESSION['SB_LOGIN_STRING'] = null; 27 | unset($GLOBALS['_SESSION']['SB_LOGIN_STRING']); 28 | } 29 | 30 | if (isset($_SESSION['SB_LOGIN_USER'])) { 31 | $_SESSION['SB_LOGIN_USER'] = null; 32 | unset($GLOBALS['_SESSION']['SB_LOGIN_USER']); 33 | } 34 | 35 | if (isset($_SESSION['SB_LOGIN_PASS'])) { 36 | $_SESSION['SB_LOGIN_PASS'] = null; 37 | unset($GLOBALS['_SESSION']['SB_LOGIN_PASS']); 38 | } 39 | 40 | header("Location: login.php"); 41 | 42 | ?> 43 | -------------------------------------------------------------------------------- /query.php: -------------------------------------------------------------------------------- 1 | 13 | Reviewed : 2016 Carlos Martín Arnillas 14 | 15 | */ 16 | 17 | include "functions.php"; 18 | 19 | loginCheck(); 20 | 21 | if (isset($db)) 22 | $conn->selectDB($db); 23 | 24 | if (isset($_POST['query'])) 25 | $query = $_POST['query']; 26 | 27 | echo '
'; 28 | 29 | if (isset($db)) { 30 | echo '' . sprintf(__("Run a query on the %s database"), $db) . '.'; 31 | } 32 | 33 | if (isset($query)) { 34 | $displayQuery = $query; 35 | } else if (isset($db) && isset($table)) { 36 | $displayQuery = "SELECT * FROM `$table` LIMIT 100"; 37 | } 38 | 39 | ?> 40 | 41 |
42 | 43 | 44 | 52 | 55 | 56 |
45 | 51 | 53 | " /> 54 |
57 |
58 | 59 |
60 | 61 | '; 66 | 67 | require "includes/browse.php"; 68 | 69 | echo ''; 70 | } 71 | 72 | ?> 73 | 78 | -------------------------------------------------------------------------------- /serve.php: -------------------------------------------------------------------------------- 1 | 13 | Reviewed : 2016 Carlos Martín Arnillas 14 | 15 | */ 16 | 17 | include "config.php"; 18 | 19 | function compressCSS($input) { 20 | // remove comments 21 | $input = preg_replace("/\/\*.*\*\//Us", "", $input); 22 | 23 | // remove unnecessary characters 24 | $input = str_replace(":0px", ":0", $input); 25 | $input = str_replace(":0em", ":0", $input); 26 | $input = str_replace(" 0px", " 0", $input); 27 | $input = str_replace(" 0em", " 0", $input); 28 | $input = str_replace(";}", "}", $input); 29 | 30 | // remove spaces, etc 31 | $input = preg_replace('/\s\s+/', ' ', $input); 32 | $input = str_replace(" {", "{", $input); 33 | $input = str_replace("{ ", "{", $input); 34 | $input = str_replace("\n{", "{", $input); 35 | $input = str_replace("{\n", "{", $input); 36 | $input = str_replace(" }", "}", $input); 37 | $input = str_replace("} ", "}", $input); 38 | $input = str_replace(": ", ":", $input); 39 | $input = str_replace(" :", ":", $input); 40 | $input = str_replace(";\n", ";", $input); 41 | $input = str_replace(" ;", ";", $input); 42 | $input = str_replace("; ", ";", $input); 43 | $input = str_replace(", ", ",", $input); 44 | 45 | return trim($input); 46 | } 47 | 48 | function compressJS($input) { 49 | 50 | // remove comments 51 | $input = preg_replace("/\/\/.*\n/Us", "", $input); 52 | $input = preg_replace("/\/\*.*\*\//Us", "", $input); 53 | 54 | // remove spaces, etc 55 | $input = preg_replace("/\t/", "", $input); 56 | $input = preg_replace("/\n\n+/m", "\n", $input); 57 | $input = str_replace(";\n", ";", $input); 58 | $input = str_replace(" = ", "=", $input); 59 | $input = str_replace(" == ", "==", $input); 60 | $input = str_replace(" || ", "||", $input); 61 | $input = str_replace(" && ", "&&", $input); 62 | $input = str_replace(")\n{", "){", $input); 63 | $input = str_replace("if (", "if(", $input); 64 | 65 | return trim($input); 66 | } 67 | 68 | if (isset($_GET['file'])) { 69 | 70 | $filename = $_GET['file']; 71 | 72 | if (!(strpos($filename, "css/") === 0 || strpos($filename, "themes/") === 0 || strpos($filename, "js/") === 0)) 73 | exit; 74 | 75 | if (strpos($filename, "..") !== false) 76 | exit; 77 | 78 | if (file_exists($filename)) { 79 | if (extension_loaded('zlib') && ((isset($sbconfig['EnableGzip']) && $sbconfig['EnableGzip'] == true) || !isset($sbconfig['EnableGzip']))) { 80 | ob_start("ob_gzhandler"); 81 | } else { 82 | ob_start(); 83 | } 84 | 85 | $last_modified_time = filemtime($filename); 86 | $etag = md5_file($filename); 87 | 88 | header("Last-Modified: " . gmdate("D, d M Y H:i:s", $last_modified_time) . " GMT"); 89 | header("Expires: " . gmdate("D, d M Y H:i:s", time()+24*60*60*60) . " GMT"); 90 | header("Etag: $etag"); 91 | 92 | if ((array_key_exists('HTTP_IF_MODIFIED_SINCE', $_SERVER) && @strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) == $last_modified_time) || (array_key_exists('HTTP_IF_NONE_MATCH', $_SERVER) && trim($_SERVER['HTTP_IF_NONE_MATCH']) == $etag)) { 93 | header("HTTP/1.1 304 Not Modified"); 94 | exit; 95 | } 96 | 97 | $contents = file_get_contents($filename); 98 | 99 | if (substr($filename, -4) == ".css") { 100 | header("Content-Type: text/css; charset=utf-8"); 101 | $contents = compressCSS($contents); 102 | } else if (substr($filename, -3) == ".js" && strpos($filename, "mootools") === false) { 103 | header("Content-Type: application/x-javascript; charset=utf-8"); 104 | $contents = compressJS($contents); 105 | } else if (substr($filename, -3) == ".js") { 106 | header("Content-Type: application/x-javascript; charset=utf-8"); 107 | } 108 | 109 | echo $contents; 110 | 111 | ob_end_flush(); 112 | } else { 113 | echo "File doesn't exist!"; 114 | } 115 | } 116 | 117 | ?> 118 | -------------------------------------------------------------------------------- /themes/bittersweet/css/ie.css: -------------------------------------------------------------------------------- 1 | #header { 2 | padding-bottom: 4px; 3 | } 4 | 5 | #rightside { 6 | padding-bottom: 0 !important; 7 | } 8 | 9 | .leftchecks { 10 | margin-left: -22px !important; 11 | } 12 | .browsetab .leftchecks { 13 | margin-left: -38px !important; 14 | } 15 | 16 | .manip { 17 | padding-top: 0 !important; 18 | padding-bottom: 1px !important; 19 | } 20 | .manip dt { 21 | padding: 0 5px 0 1px !important; 22 | } 23 | 24 | .browsetab .gridheader, .users .gridheader { 25 | margin-top: -15px; 26 | } 27 | 28 | .dblist { 29 | float: none !important; 30 | } 31 | .dblist ul li { 32 | float: none !important; 33 | } 34 | 35 | .sublist { 36 | width: 225px; 37 | } 38 | 39 | #leftside { 40 | width: 225px !important; 41 | } 42 | #rightside { 43 | margin-left: 225px !important; 44 | } -------------------------------------------------------------------------------- /themes/bittersweet/css/main.css: -------------------------------------------------------------------------------- 1 | body { 2 | background: rgb(255, 255, 255) url(../images/initLoad-dark.png) no-repeat 50% 125px; 3 | } 4 | 5 | #header { 6 | background: rgb(80, 80, 80) url(../images/header.png) repeat-x; 7 | } 8 | 9 | #headerlogo { 10 | width: 185px !important; 11 | } 12 | #leftside { 13 | width: 205px !important; 14 | overflow-y: hidden; 15 | } 16 | #rightside { 17 | margin-left: 205px !important; 18 | } 19 | #sidemenu { 20 | overflow-x: hidden; 21 | } 22 | 23 | #bottom { 24 | background: transparent url(../../../images/window-shadow-bottom.png) repeat-x scroll 0px -7px; 25 | } 26 | 27 | #innercontent a { 28 | color: steelBlue; 29 | } 30 | #innercontent a:hover { 31 | color: rgb(50, 50, 50); 32 | } 33 | 34 | h3, h4 { 35 | color: rgb(135, 135, 115); 36 | text-transform: uppercase; 37 | font-weight: normal; 38 | } 39 | h3 { 40 | font-size: 12px; 41 | } 42 | h4 { 43 | border-bottom: 1px solid rgb(210, 210, 210); 44 | line-height: 1.3; 45 | font-size: 14px; 46 | } 47 | 48 | #headerinfo a { 49 | color: rgb(200, 200, 200) !important; 50 | text-decoration: none; 51 | } 52 | #headerinfo a:hover { 53 | color: rgb(250, 250, 250) !important; 54 | } 55 | 56 | .grid { 57 | border-color: rgb(220, 220, 220) rgb(190, 190, 190) rgb(190, 190, 190) rgb(190, 190, 190); 58 | } 59 | 60 | .alternator { 61 | border-bottom-color: transparent; 62 | background: white; 63 | } 64 | .alternator2 { 65 | background: rgb(245, 245, 245); 66 | } 67 | .highlighted { 68 | border-bottom-color: rgb(210, 210, 210) !important; 69 | background: rgb(230, 230, 215) !important; 70 | } 71 | 72 | .paginator a { 73 | color: rgb(125, 125, 125) !important; 74 | } 75 | 76 | .dblistheader { 77 | color: rgb(150, 150, 150) !important; 78 | } 79 | .dblist { 80 | float: left; 81 | } 82 | .dblist ul li { 83 | float: left; 84 | clear: left; 85 | } 86 | .dblist ul li a { 87 | display: inline !important; 88 | border-width: 0 !important; 89 | } 90 | .dblist ul li a .menutext { 91 | color: rgb(80, 80, 80); 92 | margin-left: 0 !important; 93 | float: left; 94 | } 95 | .dblist ul li a:hover .menutext { 96 | color: rgb(40, 40, 40); 97 | } 98 | .dblist ul li a .menuicon { 99 | color: rgb(150, 150, 150) !important; 100 | } 101 | .dblist ul li.selected>a { 102 | font-weight: bold; 103 | } 104 | .sublist { 105 | float: left; 106 | clear: left; 107 | line-height: 18px; 108 | } 109 | .sublist li a { 110 | color: rgb(80, 80, 80); 111 | } 112 | .sublist li a:hover { 113 | color: rgb(40, 40, 40); 114 | } 115 | .subcount { 116 | color: rgb(150, 150, 150); 117 | } 118 | 119 | #loginform { 120 | padding: 3px; 121 | border: 1px solid rgb(200, 200, 200); 122 | } 123 | #loginform .loginspacer { 124 | background: #E9EBDF !important; 125 | padding: 10px 15px 10px 11px !important; 126 | } 127 | .loginheader { 128 | border-bottom-color: rgb(200, 200, 200); 129 | } 130 | #loginform .field { 131 | color: #777; 132 | } 133 | 134 | #toptabs ul li a { 135 | color: rgb(220, 220, 220); 136 | } 137 | #toptabs ul li a .rowcount { 138 | color: rgb(175, 175, 175); 139 | } 140 | #toptabs ul li a:hover { 141 | color: rgb(250, 250, 250); 142 | } 143 | #toptabs ul li.selected a { 144 | color: rgb(250, 250, 250); 145 | font-weight: bold; 146 | } 147 | #toptabs ul li.selected a .rowcount { 148 | color: rgb(225, 225, 225); 149 | } 150 | #toptabs ul li.deactivated a { 151 | color: rgb(135, 135, 135) !important; 152 | } 153 | #toptabs ul li.deactivated a .rowcount { 154 | color: rgb(175, 175, 175) !important; 155 | } -------------------------------------------------------------------------------- /themes/bittersweet/images/header.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Frecuencio/sqlbuddy-php7/6614b9d3dd0321bb6588043f739a78071c3f3e93/themes/bittersweet/images/header.png -------------------------------------------------------------------------------- /themes/bittersweet/images/initLoad-dark.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Frecuencio/sqlbuddy-php7/6614b9d3dd0321bb6588043f739a78071c3f3e93/themes/bittersweet/images/initLoad-dark.png -------------------------------------------------------------------------------- /themes/classic/css/ie.css: -------------------------------------------------------------------------------- 1 | #header { 2 | padding-bottom: 4px; 3 | } 4 | 5 | #rightside { 6 | padding-bottom: 0 !important; 7 | } 8 | 9 | .leftchecks { 10 | margin-left: -22px !important; 11 | } 12 | .browsetab .leftchecks { 13 | margin-left: -38px !important; 14 | } 15 | 16 | .manip { 17 | padding-top: 0 !important; 18 | padding-bottom: 1px !important; 19 | } 20 | .manip dt { 21 | padding: 0 5px 0 1px !important; 22 | } 23 | 24 | .browsetab .gridheader, .users .gridheader { 25 | margin-top: -15px; 26 | } 27 | 28 | .sublist li a { 29 | padding-top: 0 !important; 30 | padding-bottom: 1px !important; 31 | } -------------------------------------------------------------------------------- /themes/classic/css/main.css: -------------------------------------------------------------------------------- 1 | html { 2 | background: rgb(125, 125, 125) url(../images/shading.png); 3 | } 4 | 5 | #header { 6 | background: url(../images/header.png) repeat-x bottom; 7 | border-bottom: 1px solid rgb(150, 150, 150); 8 | } 9 | 10 | h3, h4 { 11 | color: steelblue; 12 | } 13 | 14 | #innercontent { 15 | background: white; 16 | border-color: rgb(75, 75, 75); 17 | border-width: 0 2px; 18 | border-style: solid; 19 | } 20 | 21 | .corners { 22 | background: rgb(75, 75, 75); 23 | height: 2px; 24 | } 25 | .corners div { 26 | width: 4px; 27 | height: 4px; 28 | background-repeat: no-repeat; 29 | } 30 | .tl { 31 | background: url(../images/corner-tl.png); 32 | float: left; 33 | } 34 | .tr { 35 | background: url(../images/corner-tr.png); 36 | float: right; 37 | } 38 | .bl { 39 | background: url(../images/corner-bl.png); 40 | float: left; 41 | margin-top: -2px; 42 | } 43 | .br { 44 | background: url(../images/corner-br.png); 45 | float: right; 46 | margin-top: -2px; 47 | } 48 | 49 | #headerinfo a { 50 | color: rgb(215, 215, 215) !important; 51 | text-shadow: rgb(50, 50, 50) 0 1px 0; 52 | } 53 | #headerinfo a:hover { 54 | color: #fff !important; 55 | } 56 | 57 | #loginform { 58 | padding: 7px; 59 | background: url(../../../images/transparent.png); 60 | } 61 | #loginform .loginspacer { 62 | background: white; 63 | } 64 | 65 | .dblistheader { 66 | color: rgb(220, 220, 220); 67 | text-shadow: rgb(75, 75, 75) 0px 1px 0px; 68 | } 69 | 70 | .dblist ul li a .menutext { 71 | color: #fff; 72 | } 73 | .dblist ul li a .menuicon { 74 | color: rgb(220, 220, 220); 75 | } 76 | .dblist ul li.selected>a { 77 | background: rgb(90, 90, 90) !important; 78 | border-color: rgb(70, 70, 70); 79 | } 80 | .sublist li a { 81 | color: #fff; 82 | } 83 | .subcount { 84 | color: rgb(200, 200, 200); 85 | } 86 | 87 | #toptabs ul li a { 88 | color: rgb(215, 215, 215); 89 | text-shadow: rgb(50, 50, 50) 0 1px 0; 90 | font-weight: bold; 91 | } 92 | #toptabs ul li a .rowcount { 93 | color: rgb(235, 235, 235); 94 | } 95 | #toptabs ul li a:hover { 96 | color: #fff; 97 | } 98 | #toptabs ul li.selected a { 99 | color: #fff; 100 | font-weight: bold; 101 | text-shadow: rgb(50, 50, 50) 0 1px 0; 102 | } 103 | #toptabs ul li.selected a .rowcount { 104 | color: rgb(235, 235, 235); 105 | } 106 | #toptabs ul li.deactivated a { 107 | color: rgb(175, 175, 175) !important; 108 | } 109 | #toptabs ul li.deactivated a .rowcount { 110 | color: rgb(175, 175, 175) !important; 111 | } -------------------------------------------------------------------------------- /themes/classic/images/corner-bl.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Frecuencio/sqlbuddy-php7/6614b9d3dd0321bb6588043f739a78071c3f3e93/themes/classic/images/corner-bl.png -------------------------------------------------------------------------------- /themes/classic/images/corner-br.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Frecuencio/sqlbuddy-php7/6614b9d3dd0321bb6588043f739a78071c3f3e93/themes/classic/images/corner-br.png -------------------------------------------------------------------------------- /themes/classic/images/corner-tl.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Frecuencio/sqlbuddy-php7/6614b9d3dd0321bb6588043f739a78071c3f3e93/themes/classic/images/corner-tl.png -------------------------------------------------------------------------------- /themes/classic/images/corner-tr.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Frecuencio/sqlbuddy-php7/6614b9d3dd0321bb6588043f739a78071c3f3e93/themes/classic/images/corner-tr.png -------------------------------------------------------------------------------- /themes/classic/images/header.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Frecuencio/sqlbuddy-php7/6614b9d3dd0321bb6588043f739a78071c3f3e93/themes/classic/images/header.png -------------------------------------------------------------------------------- /themes/classic/images/shading.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Frecuencio/sqlbuddy-php7/6614b9d3dd0321bb6588043f739a78071c3f3e93/themes/classic/images/shading.png -------------------------------------------------------------------------------- /users.php: -------------------------------------------------------------------------------- 1 | 13 | Reviewed : 2016 Carlos Martín Arnillas 14 | 15 | */ 16 | 17 | include "functions.php"; 18 | 19 | loginCheck(); 20 | 21 | function removeAdminPrivs($priv) { 22 | if ($priv == "FILE" || $priv == "PROCESS" || $priv == "RELOAD" || $priv == "SHUTDOWN" || $priv == "SUPER") 23 | return false; 24 | else 25 | return true; 26 | } 27 | 28 | if ($_POST) { 29 | 30 | if (isset($_POST['NEWHOST'])) 31 | $newHost = $_POST['NEWHOST']; 32 | else 33 | $newHost = "localhost"; 34 | 35 | if (isset($_POST['NEWNAME'])) 36 | $newName = $_POST['NEWNAME']; 37 | 38 | if (isset($_POST['NEWPASS'])) 39 | $newPass = $_POST['NEWPASS']; 40 | 41 | if (isset($_POST['ACCESSLEVEL'])) 42 | $accessLevel = $_POST['ACCESSLEVEL']; 43 | else 44 | $accessLevel = "GLOBAL"; 45 | 46 | if ($accessLevel != "LIMITED") 47 | $accessLevel = "GLOBAL"; 48 | 49 | if (isset($_POST['DBLIST'])) 50 | $dbList = $_POST['DBLIST']; 51 | else 52 | $dbList = array(); 53 | 54 | if (isset($_POST['NEWCHOICE'])) 55 | $newChoice = $_POST['NEWCHOICE']; 56 | 57 | if (isset($_POST['NEWPRIVILEGES'])) 58 | $newPrivileges = $_POST['NEWPRIVILEGES']; 59 | 60 | if (isset($newName) && ($accessLevel == "GLOBAL" || ($accessLevel == "LIMITED" && sizeof($dbList) > 0))) { 61 | 62 | if ($newChoice == "ALL") { 63 | $privList = "ALL"; 64 | } else { 65 | 66 | if (sizeof($newPrivileges) > 0) { 67 | if ($accessLevel == "LIMITED") { 68 | $newPrivileges = array_filter($newPrivileges, "removeAdminPrivs"); 69 | } 70 | 71 | $privList = implode(", ", $newPrivileges); 72 | 73 | } else { 74 | $privList = "USAGE"; 75 | } 76 | } 77 | 78 | if ($accessLevel == "LIMITED") { 79 | foreach ($dbList as $theDb) { 80 | $newQuery = "GRANT " . $privList; 81 | 82 | $newQuery .= " ON `$theDb`.*"; 83 | 84 | $newQuery .= " TO '" . $newName . "'@'" . $newHost . "'"; 85 | 86 | if ($newPass) 87 | $newQuery .= " IDENTIFIED BY '" . $newPass . "'"; 88 | 89 | if (isset($_POST['GRANTOPTION'])) 90 | $newQuery .= " WITH GRANT OPTION"; 91 | 92 | $conn->query($newQuery) or ($dbError = $conn->error()); 93 | } 94 | } else { 95 | $newQuery = "GRANT " . $privList; 96 | 97 | $newQuery .= " ON *.*"; 98 | 99 | $newQuery .= " TO '" . $newName . "'@'" . $newHost . "'"; 100 | 101 | if ($newPass) 102 | $newQuery .= " IDENTIFIED BY '" . $newPass . "'"; 103 | 104 | if (isset($_POST['GRANTOPTION'])) 105 | $newQuery .= " WITH GRANT OPTION"; 106 | 107 | $conn->query($newQuery) or ($dbError = $conn->error()); 108 | } 109 | 110 | $conn->query("FLUSH PRIVILEGES") or ($dbError = $conn->error()); 111 | 112 | } 113 | } 114 | 115 | $connected = $conn->selectDB("mysql"); 116 | 117 | // delete users 118 | if (isset($_POST['deleteUsers']) && $connected) { 119 | $deleteUsers = $_POST['deleteUsers']; 120 | 121 | // boom! 122 | $userList = explode(";", $deleteUsers); 123 | 124 | foreach ($userList as $each) { 125 | $split = explode("@", $each, 2); 126 | 127 | if (isset($split[0])) 128 | $user = trim($split[0]); 129 | 130 | if (isset($split[1])) 131 | $host = trim($split[1]); 132 | 133 | if (isset($user) && isset($host)) { 134 | $conn->query("REVOKE ALL PRIVILEGES ON *.* FROM '$user'@'$host'"); 135 | $conn->query("REVOKE GRANT OPTION ON *.* FROM '$user'@'$host'"); 136 | $conn->query("DELETE FROM `user` WHERE `User`='$user' AND `Host`='$host'"); 137 | $conn->query("DELETE FROM `db` WHERE `User`='$user' AND `Host`='$host'"); 138 | $conn->query("DELETE FROM `tables_priv` WHERE `User`='$user' AND `Host`='$host'"); 139 | $conn->query("DELETE FROM `columns_priv` WHERE `User`='$user' AND `Host`='$host'"); 140 | } 141 | } 142 | $conn->query("FLUSH PRIVILEGES"); 143 | } 144 | 145 | if (isset($dbError)) { 146 | echo '
'; 147 | echo '' . __("Error performing operation") . '

' . $dbError . '

'; 148 | echo '
'; 149 | } 150 | 151 | ?> 152 | 153 |
154 | 155 | query("SELECT * FROM `user`"); 160 | 161 | if ($conn->isResultSet($userSql)) { 162 | 163 | ?> 164 | 165 | 166 | 167 | 176 | 177 |
168 | ' . __("All") . '  ' . __("None") . ''; 171 | echo '     ' . __("With selected") . ':  ' . __("Edit") . '  ' . __("Delete") . ''; 172 | 173 | ?> 174 | 175 |
178 | 179 | '; 182 | 183 | echo '
 
'; 184 | 185 | echo '
'; 186 | echo '
'; 187 | echo ''; 188 | echo ''; 189 | echo ''; 190 | echo ''; 191 | echo ''; 192 | echo ''; 193 | echo ''; 194 | echo '
' . __("Host") . '
' . __("User") . '
'; 195 | echo '
'; 196 | echo '
'; 197 | 198 | echo '
'; 199 | 200 | $m = 0; 201 | 202 | while ($userRow = $conn->fetchAssoc($userSql)) { 203 | $queryBuilder = $userRow['User'] . "@" . $userRow['Host']; 204 | echo '
'; 212 | } 213 | 214 | echo '
'; 215 | 216 | $userSql = $conn->query("SELECT * FROM `user`"); 217 | 218 | echo '
'; 219 | 220 | if ($conn->isResultSet($userSql)) { 221 | $m = 0; 222 | 223 | while ($userRow = $conn->fetchAssoc($userSql)) { 224 | 225 | echo '
'; 232 | echo ''; 233 | echo ''; 234 | echo ''; 235 | echo ''; 236 | echo ''; 237 | echo '
' . $userRow['Host'] . '
' . $userRow['User'] . '
'; 238 | echo '
'; 239 | 240 | $m++; 241 | } 242 | } 243 | 244 | echo '
'; 245 | echo '
'; 246 | 247 | } 248 | 249 | $hasPermissions = false; 250 | 251 | // check to see if this user has proper permissions to manage users 252 | $checkSql = $conn->query("SELECT `Grant_priv` FROM `user` WHERE `Host`='" . $conn->getOptionValue("host") . "' AND `User`='" . $_SESSION['SB_LOGIN_USER'] . "' LIMIT 1"); 253 | 254 | if ($conn->isResultSet($checkSql)) { 255 | $grantValue = $conn->result($checkSql, 0, "Grant_priv"); 256 | 257 | if ($grantValue == "Y") { 258 | $hasPermissions = true; 259 | } 260 | } 261 | 262 | if ($hasPermissions) { 263 | 264 | ?> 265 | 266 |
267 |

268 | 269 |
270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | listDatabases(); 286 | 287 | if ($conn->isResultSet($dbList)) { 288 | 289 | ?> 290 | 291 | 292 | 313 | 314 | 319 | 320 | 321 | 401 | 402 |
:
:
:
: 293 |
294 | 295 | 296 | 311 | 312 |
: 322 |
323 | 324 | 325 | 399 | 400 |
403 | 404 | 405 | 406 | 407 | 410 | 411 |
: 408 | 409 |
412 | 413 |
414 | " /> 415 |
416 |
417 |
418 | 422 |

423 |

424 | 429 |
430 |

431 |

432 |
433 | 437 | 438 | 439 | 442 | --------------------------------------------------------------------------------