├── LICENSE ├── README.md └── src ├── 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-php4.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 | Copyright (c) 2008 Calvin Lough 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | | :warning:   SQL Buddy is no longer actively maintained. | 2 | |-------------------------------------------------------------------| 3 | 4 | This software is still free to use under the license provided below, but users should be aware 5 | that it is not currently maintained. No additional releases, including security releases, will 6 | be made available. Caveat emptor. 7 | 8 | 9 | SQL Buddy 10 | =========== 11 | 12 | SQL Buddy is a phpMyAdmin alternative with a focus on usability. 13 | 14 | ![Screenshot 1](https://raw.github.com/calvinlough/sqlbuddy/gh-pages/images/screenshot1.png) 15 | ![Screenshot 2](https://raw.github.com/calvinlough/sqlbuddy/gh-pages/images/screenshot2.png) 16 | ![Screenshot 3](https://raw.github.com/calvinlough/sqlbuddy/gh-pages/images/screenshot3.png) 17 | 18 | ## Features 19 | 20 | * Create and drop databases and tables 21 | * View, edit, insert and delete table rows 22 | * Execute custom SQL and view the output 23 | * Import and export databases and tables to SQL and CSV formats 24 | * Add, edit and delete MySQL users 25 | * Ships with 47 translations (including Esperanto!) 26 | 27 | ## Download 28 | 29 | **[Download v1.3.3](https://github.com/calvinlough/sqlbuddy/raw/gh-pages/sqlbuddy.zip)** 30 | 31 | ## Installation 32 | 33 | * Download the file above and unzip it 34 | * Upload the sqlbuddy folder to your web server 35 | * Point your browser to the sqlbuddy folder 36 | * Log in using your existing MySQL credentials 37 | 38 | ## Requirements 39 | 40 | * PHP 4.3+ 41 | * MySQL 4+ 42 | 43 | ## Help 44 | 45 | If you need help, a forum is available at http://groups.google.com/group/sql-buddy/topics 46 | 47 | ## License 48 | 49 | Copyright © 2013 Calvin Lough 50 | 51 | Permission is hereby granted, free of charge, to any person obtaining 52 | a copy of this software and associated documentation files (the 53 | "Software"), to deal in the Software without restriction, including 54 | without limitation the rights to use, copy, modify, merge, publish, 55 | distribute, sublicense, and/or sell copies of the Software, and to 56 | permit persons to whom the Software is furnished to do so, subject to 57 | the following conditions: 58 | 59 | The above copyright notice and this permission notice shall be 60 | included in all copies or substantial portions of the Software. 61 | 62 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 63 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 64 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 65 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 66 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 67 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 68 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 69 | -------------------------------------------------------------------------------- /src/ajaxcreatetable.php: -------------------------------------------------------------------------------- 1 | 13 | 14 | */ 15 | 16 | include "functions.php"; 17 | 18 | loginCheck(); 19 | 20 | if (isset($db)) 21 | $conn->selectDB($db); 22 | 23 | if (isset($_POST['query'])) { 24 | 25 | $queryList = splitQueryText($_POST['query']); 26 | 27 | foreach ($queryList as $query) { 28 | $sql = $conn->query($query) or ($dbError = $conn->error()); 29 | } 30 | 31 | if (isset($dbError)) { 32 | echo $dbError; 33 | } 34 | 35 | } 36 | 37 | ?> -------------------------------------------------------------------------------- /src/ajaxfulltext.php: -------------------------------------------------------------------------------- 1 | 13 | 14 | */ 15 | 16 | include "functions.php"; 17 | 18 | loginCheck(); 19 | 20 | if (isset($db)) 21 | $conn->selectDB($db); 22 | 23 | if (isset($_POST['query'])) { 24 | 25 | $queryList = splitQueryText($_POST['query']); 26 | 27 | foreach ($queryList as $query) { 28 | $sql = $conn->query($query); 29 | } 30 | } 31 | 32 | if ($conn->getAdapter() == "mysql") { 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 | ?> -------------------------------------------------------------------------------- /src/ajaximportfile.php: -------------------------------------------------------------------------------- 1 | 13 | 14 | */ 15 | 16 | include "functions.php"; 17 | 18 | loginCheck(); 19 | 20 | if (isset($db)) 21 | $conn->selectDB($db); 22 | 23 | function stripCommentLines($in) { 24 | if (substr($in, 0, 2) == "--") 25 | $in = ''; 26 | 27 | return $in; 28 | } 29 | 30 | if (isset($_POST) || isset($_FILES)) { 31 | 32 | if (isset($_FILES['INPUTFILE']['tmp_name'])) 33 | $file = $_FILES['INPUTFILE']['tmp_name']; 34 | 35 | if (isset($_POST['FORMAT'])) 36 | $format = $_POST['FORMAT']; 37 | 38 | if (!(isset($format) && $format == "CSV")) 39 | $format = "SQL"; 40 | 41 | if (isset($_POST['IGNOREFIRST'])) 42 | $ignoreFirst = $_POST['IGNOREFIRST']; 43 | 44 | $first = true; 45 | 46 | // for csv 47 | if (isset($format) && $format == "CSV" && isset($table)) { 48 | $columnCount = 0; 49 | 50 | $structureSQL = $conn->describeTable($table); 51 | 52 | if ($conn->isResultSet($structureSQL)) { 53 | while ($structureRow = $conn->fetchAssoc($structureSQL)) { 54 | $columnCount++; 55 | } 56 | } 57 | } 58 | 59 | $insertCount = 0; 60 | $skipCount = 0; 61 | 62 | if (isset($file) && is_uploaded_file($file)) { 63 | if (isset($format) && $format == "SQL") { 64 | $lines = file($file); 65 | 66 | // the file() function doesn't handle mac line endings correctly 67 | if (sizeof($lines) == 1 && strpos($lines[0], "\r") > 0) { 68 | $lines = explode("\r", $lines[0]); 69 | } 70 | 71 | $commentFree = array_map("stripCommentLines", $lines); 72 | 73 | $contents = trim(implode('', $commentFree)); 74 | 75 | $statements = splitQueryText($contents); 76 | } else { 77 | $statements = file($file); 78 | 79 | // see previous comment 80 | if (sizeof($statements) == 1 && strpos($statements[0], "\r") > 0) { 81 | $statements = explode("\r", $statements[0]); 82 | } 83 | } 84 | 85 | foreach ($statements as $statement) { 86 | $statement = trim($statement); 87 | 88 | if ($statement) { 89 | if (isset($format) && $format == "SQL") { 90 | $importQuery = $conn->query($statement) or ($dbErrors[] = $conn->error()); 91 | 92 | $affected = (int)($conn->affectedRows($importQuery)); 93 | $insertCount += $affected; 94 | } else if (isset($format) && $format == "CSV" && isset($table)) { 95 | if (!(isset($ignoreFirst) && $first)) { 96 | preg_match_all('/"(([^"]|"")*)"/i', $statement, $matches); 97 | 98 | $rawValues = $matches[1]; 99 | 100 | for ($i=0; $iescapeString($rawValues[$i]); 103 | } 104 | 105 | $values = implode("','", $rawValues); 106 | 107 | // make sure that the counts match up 108 | if (sizeof($rawValues) == $columnCount) { 109 | 110 | if ($conn->getAdapter() == "sqlite") 111 | $importQuery = $conn->query("INSERT INTO '$table' VALUES ('$values')") or ($dbErrors[] = $conn->error()); 112 | else 113 | $importQuery = $conn->query("INSERT INTO `$table` VALUES ('$values')") or ($dbErrors[] = $conn->error()); 114 | 115 | $affected = (int)($conn->affectedRows($importQuery)); 116 | 117 | $insertCount += $affected; 118 | } else { 119 | $skipCount++; 120 | } 121 | } 122 | $first = false; 123 | } 124 | } 125 | } 126 | } 127 | 128 | $message = ""; 129 | 130 | if (!isset($statements)) { 131 | $message .= __("Either the file could not be read or it was empty") . "
"; 132 | } else if ($format == "SQL") { 133 | $message .= sprintf(__p("%d statement was executed from the file", "%d statements were executed from the file", $insertCount), $insertCount) . ".
"; 134 | } else if ($format == "CSV") { 135 | if (isset($insertCount) && $insertCount > 0) { 136 | $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) . ".
"; 137 | } 138 | if (isset($skipCount) && $skipCount > 0) { 139 | $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) . ".
"; 140 | } 141 | } 142 | 143 | if (isset($dbErrors)) { 144 | $message .= __("The following errors were reported") . ":
"; 145 | foreach ($dbErrors as $merr) { 146 | $message .= " - " . $merr . "
"; 147 | } 148 | } 149 | 150 | ?> 152 | 153 | 154 | 155 | 156 | 157 | 163 | 164 | 165 | 166 | -------------------------------------------------------------------------------- /src/ajaxquery.php: -------------------------------------------------------------------------------- 1 | 13 | 14 | */ 15 | 16 | include "functions.php"; 17 | 18 | loginCheck(); 19 | 20 | if (isset($db)) 21 | $conn->selectDB($db); 22 | 23 | if (isset($_POST['query'])) { 24 | $queryList = splitQueryText($_POST['query']); 25 | 26 | foreach ($queryList as $query) { 27 | $sql = $conn->query($query); 28 | } 29 | } 30 | 31 | //return the first field from the first row 32 | if (!isset($_POST['silent']) && $conn->isResultSet($sql)) { 33 | $row = $conn->fetchArray($sql); 34 | echo nl2br(htmlentities($row[0], ENT_QUOTES, 'UTF-8')); 35 | } 36 | 37 | ?> -------------------------------------------------------------------------------- /src/ajaxsavecolumnedit.php: -------------------------------------------------------------------------------- 1 | 13 | 14 | */ 15 | 16 | include "functions.php"; 17 | 18 | loginCheck(); 19 | 20 | if (isset($db)) 21 | $conn->selectDB($db); 22 | 23 | if (isset($_POST['runQuery'])) { 24 | $query = $_POST['runQuery']; 25 | 26 | $conn->query($query) or ($dbError = $conn->error()); 27 | 28 | echo "{\n"; 29 | echo " \"formupdate\": \"" . $_GET['form'] . "\",\n"; 30 | echo " \"errormess\": \""; 31 | if (isset($dbError)) 32 | echo $dbError; 33 | echo "\"\n"; 34 | echo '}'; 35 | 36 | } 37 | 38 | ?> -------------------------------------------------------------------------------- /src/ajaxsaveedit.php: -------------------------------------------------------------------------------- 1 | 13 | 14 | */ 15 | 16 | include "functions.php"; 17 | 18 | loginCheck(); 19 | 20 | if (isset($db)) 21 | $conn->selectDB($db); 22 | 23 | if ($_POST && isset($table)) { 24 | 25 | $insertChoice = ""; 26 | 27 | if (isset($_POST['SB_INSERT_CHOICE'])) { 28 | $insertChoice = $_POST['SB_INSERT_CHOICE']; 29 | } 30 | 31 | $structureSql = $conn->describeTable($table); 32 | 33 | if ($conn->getAdapter() == "mysql") { 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 | } else if ($conn->getAdapter() == "sqlite") { 40 | foreach ($structureRow as $column) { 41 | $pairs[$column[0]] = ''; 42 | } 43 | } 44 | 45 | foreach ($_POST as $key=>$value) { 46 | if ($key != "SB_INSERT_CHOICE") { 47 | if (is_array($value)) { 48 | $value = implode(",", $value); 49 | } 50 | 51 | $pairs[$key] = $conn->escapeString($value); 52 | } 53 | } 54 | 55 | if (isset($pairs)) { 56 | 57 | if ($insertChoice != "INSERT") { 58 | $updates = ""; 59 | 60 | foreach ($pairs as $keyname=>$value) { 61 | if ($conn->getAdapter() == "mysql") { 62 | if (isset($types) && substr($value, 0, 2) == "0x" && isset($binaryDTs) && in_array($types[$keyname], $binaryDTs)) { 63 | $updates .= "`" . $keyname . "`=" . $value . ","; 64 | } else if (!$value && !($value != '' && (int)$value == 0) && $nulls[$keyname] == "YES") { 65 | $updates .= "`" . $keyname . "`=NULL,"; 66 | } else { 67 | $updates .= "`" . $keyname . "`='" . $value . "',"; 68 | } 69 | } 70 | } 71 | 72 | $updates = substr($updates, 0, -1); 73 | 74 | if (isset($_GET['queryPart'])) 75 | $queryPart = $_GET['queryPart']; 76 | else 77 | $queryPart = ""; 78 | 79 | if ($conn->getAdapter() == "mysql") { 80 | $query = "UPDATE `$table` SET " . $updates . " " . $queryPart; 81 | } else if ($conn->getAdapter() == "sqlite") { 82 | $query = "UPDATE '$table' SET " . $updates . " " . $queryPart; 83 | } 84 | 85 | } else { 86 | $columns = ""; 87 | $values = ""; 88 | 89 | foreach ($pairs as $keyname=>$value) { 90 | 91 | if ($conn->getAdapter() == "mysql") { 92 | $columns .= "`" . $keyname . "`,"; 93 | } else if ($conn->getAdapter() == "sqlite") { 94 | $columns .= "'" . $keyname . "',"; 95 | } 96 | 97 | if (isset($types) && substr($value, 0, 2) == "0x" && isset($binaryDTs) && in_array($types[$keyname], $binaryDTs)) { 98 | $values .= $value . ","; 99 | } else { 100 | $values .= "'" . $value . "',"; 101 | } 102 | 103 | } 104 | 105 | $columns = substr($columns, 0, -1); 106 | $values = substr($values, 0, -1); 107 | 108 | if ($conn->getAdapter() == "mysql") { 109 | $query = "INSERT INTO `$table` ($columns) VALUES ($values)"; 110 | } else if ($conn->getAdapter() == "sqlite") { 111 | $query = "INSERT INTO '$table' ($columns) VALUES ($values)"; 112 | } 113 | } 114 | 115 | $conn->query($query) or ($dbError = $conn->error()); 116 | 117 | echo "{\n"; 118 | echo " \"formupdate\": \"" . $_GET['form'] . "\",\n"; 119 | echo " \"errormess\": \""; 120 | if (isset($dbError)) 121 | echo $dbError; 122 | echo "\"\n"; 123 | echo '}'; 124 | 125 | } 126 | } 127 | 128 | ?> -------------------------------------------------------------------------------- /src/ajaxsaveuseredit.php: -------------------------------------------------------------------------------- 1 | 13 | 14 | */ 15 | 16 | include "functions.php"; 17 | 18 | loginCheck(); 19 | 20 | $conn->selectDB("mysql"); 21 | 22 | function removeAdminPrivs($priv) { 23 | if ($priv == "FILE" || $priv == "PROCESS" || $priv == "RELOAD" || $priv == "SHUTDOWN" || $priv == "SUPER") 24 | return false; 25 | else 26 | return true; 27 | } 28 | 29 | if (isset($_GET['user'])) 30 | $user = $_GET['user']; 31 | 32 | if (isset($_POST['NEWPASS'])) 33 | $newPass = $_POST['NEWPASS']; 34 | 35 | if (isset($_POST['CHOICE'])) 36 | $choice = $_POST['CHOICE']; 37 | 38 | if (isset($_POST['ACCESSLEVEL'])) 39 | $accessLevel = $_POST['ACCESSLEVEL']; 40 | else 41 | $accessLevel = "GLOBAL"; 42 | 43 | if ($accessLevel != "LIMITED") 44 | $accessLevel = "GLOBAL"; 45 | 46 | if (isset($_POST['DBLIST'])) 47 | $dbList = $_POST['DBLIST']; 48 | else 49 | $dbList = array(); 50 | 51 | if (isset($_POST['PRIVILEGES'])) 52 | $privileges = $_POST['PRIVILEGES']; 53 | else 54 | $privileges = array(); 55 | 56 | if (isset($_POST['GRANTOPTION'])) 57 | $grantOption = $_POST['GRANTOPTION']; 58 | 59 | if (isset($user) && ($accessLevel == "GLOBAL" || ($accessLevel == "LIMITED" && sizeof($dbList) > 0))) { 60 | 61 | if ($choice == "ALL") { 62 | $privList = "ALL"; 63 | } else { 64 | if (isset($privileges) && count($privileges) > 0) 65 | $privList = implode(", ", $privileges); 66 | else 67 | $privList = "USAGE"; 68 | 69 | if (sizeof($privileges) > 0) { 70 | if ($accessLevel == "LIMITED") { 71 | $privileges = array_filter($privileges, "removeAdminPrivs"); 72 | } 73 | 74 | $privList = implode(", ", $privileges); 75 | } else { 76 | $privList = "USAGE"; 77 | } 78 | 79 | } 80 | 81 | $split = explode("@", $user); 82 | 83 | if (isset($split[0])) 84 | $name = $split[0]; 85 | 86 | if (isset($split[1])) 87 | $host = $split[1]; 88 | 89 | if (isset($name) && isset($host)) { 90 | $user = "'" . $name . "'@'" . $host . "'"; 91 | 92 | if ($accessLevel == "LIMITED") { 93 | $conn->query("DELETE FROM `db` WHERE `User`='$name' AND `Host`='$host'"); 94 | 95 | foreach ($dbList as $theDb) { 96 | $query = "GRANT " . $privList . " ON `$theDb`.* TO " . $user; 97 | 98 | if (isset($grantOption)) 99 | $query .= " WITH GRANT OPTION"; 100 | 101 | $conn->query($query) or ($dbError = $conn->error()); 102 | } 103 | } else { 104 | $conn->query("REVOKE ALL PRIVILEGES ON *.* FROM " . $user); 105 | $conn->query("REVOKE GRANT OPTION ON *.* FROM " . $user); 106 | 107 | $query = "GRANT " . $privList . " ON *.* TO " . $user; 108 | 109 | if (isset($grantOption)) 110 | $query .= " WITH GRANT OPTION"; 111 | 112 | $conn->query($query) or ($dbError = $conn->error()); 113 | } 114 | 115 | if (isset($newPass)) 116 | $conn->query("SET PASSWORD FOR '$name'@'$host' = PASSWORD('$newPass')") or ($dbError = $conn->error()); 117 | 118 | $conn->query("FLUSH PRIVILEGES") or ($dbError = $conn->error()); 119 | 120 | echo "{\n"; 121 | echo " \"formupdate\": \"" . $_GET['form'] . "\",\n"; 122 | echo " \"errormess\": \""; 123 | if (isset($dbError)) 124 | echo $dbError; 125 | echo "\"\n"; 126 | echo '}'; 127 | } 128 | } 129 | 130 | ?> -------------------------------------------------------------------------------- /src/browse.php: -------------------------------------------------------------------------------- 1 | 13 | 14 | */ 15 | 16 | include "functions.php"; 17 | 18 | loginCheck(); 19 | 20 | requireDatabaseAndTableBeDefined(); 21 | 22 | if (isset($db)) 23 | $conn->selectDB($db); 24 | 25 | //run delete queries 26 | 27 | if (isset($_POST['runQuery'])) { 28 | $runQuery = $_POST['runQuery']; 29 | 30 | $queryList = splitQueryText($runQuery); 31 | foreach ($queryList as $query) { 32 | $conn->query($query); 33 | } 34 | } 35 | 36 | if ($conn->getAdapter() == "sqlite") { 37 | $query = "SELECT * FROM '$table'"; 38 | } else { 39 | $query = "SELECT * FROM `$table`"; 40 | } 41 | 42 | $queryTable = $table; 43 | 44 | if (isset($_POST['s'])) 45 | $start = (int)($_POST['s']); 46 | else 47 | $start = 0; 48 | 49 | if (isset($_POST['sortKey'])) 50 | $sortKey = $_POST['sortKey']; 51 | 52 | if (isset($_POST['sortDir'])) 53 | $sortDir = $_POST['sortDir']; 54 | else if (isset($sortKey)) 55 | $sortDir = "ASC"; 56 | 57 | if (isset($_POST['view']) && $_POST['view'] == "1") 58 | $view = 1; 59 | else 60 | $view = 0; 61 | 62 | if (isset($sortKey) && $sortKey != "" && isset($sortDir) && $sortDir != "") { 63 | $sort = "ORDER BY `" . $sortKey . "` " . $sortDir; 64 | } else { 65 | $sort = ""; 66 | } 67 | 68 | require "includes/browse.php"; 69 | 70 | ?> -------------------------------------------------------------------------------- /src/config.php: -------------------------------------------------------------------------------- 1 | 13 | 14 | */ 15 | 16 | 17 | /* The values below are for the login.php page */ 18 | 19 | $sbconfig['DefaultAdapter'] = "mysql"; 20 | $sbconfig['DefaultHost'] = "localhost"; 21 | $sbconfig['DefaultUser'] = "root"; 22 | 23 | /* 24 | * If you want to enable automatic login, you can include your password below. To 25 | * automatically connect to SQLite, include the filename of the database instead. 26 | * Note: This is generally not recommended because it means that anyone with the 27 | * proper url will have access to your data. It should only be used on machines 28 | * that are not accessible from the internet (local testing boxes) or if you have 29 | * set up some other form of authentication. Use as your own discretion. 30 | */ 31 | 32 | // MySQL 33 | // $sbconfig['DefaultPass'] = ""; 34 | 35 | // SQLite 36 | // $sbconfig['DefaultDatabase'] = ""; 37 | 38 | /* 39 | * By default, when you view the homepage of your SQL Buddy installation, a check is 40 | * performed to see if a newer version of the application is available. No personal 41 | * information is sent about your installation and the response from the server is sent 42 | * as plain text. If, for some reason, you want to disable this behaviour, set this option 43 | * to true to disable automatic checking for updates. To learn about new versions, you can 44 | * always check the projects website at http://www.sqlbuddy.com/ 45 | */ 46 | 47 | $sbconfig['EnableUpdateCheck'] = true; 48 | 49 | /* 50 | * This controls how many rows are displayed at once on the browse tab. If you are on a local 51 | * machine or have a fast internet connection, you could increase this value. 52 | */ 53 | 54 | $sbconfig['RowsPerPage'] = 100; 55 | 56 | /* 57 | * When set to true, the server will attempt to compress all content before it is sent to the 58 | * browser. Although unlikely, there is a chance that using gzip will cause issues on certain setups. 59 | * If you are having trouble getting pages to load properly, you could try disabling gzip. 60 | */ 61 | 62 | $sbconfig['EnableGzip'] = true; 63 | 64 | ?> -------------------------------------------------------------------------------- /src/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 | } -------------------------------------------------------------------------------- /src/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 | } -------------------------------------------------------------------------------- /src/edit.php: -------------------------------------------------------------------------------- 1 | 13 | 14 | */ 15 | 16 | include "functions.php"; 17 | 18 | loginCheck(); 19 | 20 | requireDatabaseAndTableBeDefined(); 21 | 22 | if (isset($db)) 23 | $conn->selectDB($db); 24 | 25 | if (isset($table)) 26 | $structureSql = $conn->describeTable($table); 27 | 28 | if (isset($_POST['editParts'])) { 29 | $editParts = $_POST['editParts']; 30 | $editParts = explode("; ", $editParts); 31 | 32 | $totalParts = count($editParts); 33 | $counter = 0; 34 | 35 | $firstField = true; 36 | 37 | ?> 38 | 45 | 54 | 55 |
56 | 57 | 58 | isResultSet($structureSql) && $conn->getAdapter() == "mysql") { 61 | 62 | $dataSql = $conn->query("SELECT * FROM `" . $table . "` " . $part); 63 | $dataRow = $conn->fetchAssoc($dataSql); 64 | 65 | while ($structureRow = $conn->fetchAssoc($structureSql)) { 66 | 67 | preg_match("/^([a-z]+)(.([0-9]+).)?(.*)?$/", $structureRow['Type'], $matches); 68 | 69 | $curtype = $matches[1]; 70 | $cursizeQuotes = $matches[2]; 71 | $cursize = $matches[3]; 72 | $curextra = $matches[4]; 73 | 74 | echo ''; 75 | echo ''; 80 | echo ''; 81 | echo ''; 82 | echo ' 137 | 138 | 139 | describeTable($table); 143 | 144 | } else if (sizeof($structureSql) > 0 && $conn->getAdapter() == "sqlite") { 145 | 146 | $dataSql = $conn->query("SELECT * FROM '" . $table . "' " . $part); 147 | $dataRow = $conn->fetchAssoc($dataSql); 148 | 149 | foreach ($structureSql as $column) { 150 | 151 | echo ''; 152 | echo ''; 157 | echo ''; 158 | echo ''; 159 | echo ' 175 | 176 | 177 | describeTable($table); 181 | 182 | } 183 | 184 | ?> 185 | 186 | 190 | 191 | 192 | 195 | 196 |
'; 76 | if ($structureRow['Key'] == 'PRI') echo ''; 77 | echo $structureRow['Field']; 78 | if ($structureRow['Key'] == 'PRI') echo ''; 79 | echo " " . $curtype . $cursizeQuotes . ' ' . $structureRow['Extra'] . '
'; 83 | 84 | $showLargeEditor[] = "text"; 85 | $showLargeEditor[] = "mediumtext"; 86 | $showLargeEditor[] = "longtext"; 87 | 88 | if (in_array($curtype, $showLargeEditor)) { 89 | echo ''; 90 | } 91 | elseif ($curtype == "enum") { 92 | $trimmed = substr($structureRow['Type'], 6, -2); 93 | $listOptions = explode("','", $trimmed); 94 | echo ''; 104 | } 105 | elseif ($curtype == "set") { 106 | $trimmed = substr($structureRow['Type'], 5, -2); 107 | $listOptions = explode("','", $trimmed); 108 | foreach ($listOptions as $option) { 109 | $id = $option . rand(1, 1000); 110 | echo '
'; 116 | } 117 | } else { 118 | echo ''; 130 | } 131 | 132 | $firstField = false; 133 | 134 | ?> 135 | 136 |
'; 153 | if (strpos($column[1], "primary key") > 0) echo ''; 154 | echo $column[0]; 155 | if (strpos($column[1], "primary key") > 0) echo ''; 156 | echo " " . $column[1] . '
'; 160 | 161 | if (strpos($column[1], "text") !== false) { 162 | echo ''; 163 | } else { 164 | echo ''; 168 | } 169 | 170 | $firstField = false; 171 | 172 | ?> 173 | 174 |
187 |
188 | 189 |
193 | " />   194 |
197 |
198 | 199 | 200 | -------------------------------------------------------------------------------- /src/editcolumn.php: -------------------------------------------------------------------------------- 1 | 13 | 14 | */ 15 | 16 | include "functions.php"; 17 | 18 | loginCheck(); 19 | 20 | requireDatabaseAndTableBeDefined(); 21 | 22 | if (isset($db)) 23 | $conn->selectDB($db); 24 | 25 | if (isset($db)) 26 | $structureSql = $conn->query("SHOW FULL FIELDS FROM `$table`"); 27 | 28 | if (isset($_POST['editParts']) && $conn->isResultSet($structureSql)) { 29 | 30 | $editParts = $_POST['editParts']; 31 | 32 | $editParts = explode("; ", $editParts); 33 | 34 | $totalParts = count($editParts); 35 | $counter = 0; 36 | 37 | $firstField = true; 38 | 39 | ?> 40 | 47 | fetchAssoc($structureSql)) { 50 | if (in_array($structureRow['Field'], $editParts)) { 51 | echo '
'; 52 | echo '
'; 53 | echo ''; 54 | echo ''; 55 | 56 | preg_match("/^([a-z]+)(.([0-9]+).)?(.*)?$/", $structureRow['Type'], $matches); 57 | 58 | $curtype = $matches[1]; 59 | $cursizeQuotes = $matches[2]; 60 | $cursize = $matches[3]; 61 | $curextra = $matches[4]; 62 | 63 | ?> 64 | 65 | 66 | 69 | 72 | 75 | 91 | 92 | '; 100 | 101 | ?> 102 | 105 | 108 | 110 | 111 | 112 | 115 | 118 | 121 | 124 | 125 | "; 129 | echo ""; 132 | echo ""; 151 | echo ""; 152 | } 153 | 154 | ?> 155 | 156 | 159 | 164 | 165 | 166 | 171 | 172 | 173 | 176 | 177 |
67 | 68 | 70 | value="" style="width: 125px" /> 71 | 73 | 74 | 76 | 90 |
103 | 104 | 106 | " style="width: 125px" /> 107 | 109 |
113 | 114 | 116 | 117 | 119 | 120 | 122 | 123 |
"; 130 | echo __("Charset:"); 131 | echo ""; 133 | echo ""; 150 | echo "
157 | 158 | 160 | 161 | 162 | 163 |
174 | " />   175 |
178 |
179 |
180 | 181 | -------------------------------------------------------------------------------- /src/edituser.php: -------------------------------------------------------------------------------- 1 | 13 | 14 | */ 15 | 16 | include "functions.php"; 17 | 18 | loginCheck(); 19 | 20 | $conn->selectDB("mysql"); 21 | 22 | if (isset($_POST['editParts'])) { 23 | $editParts = $_POST['editParts']; 24 | 25 | $editParts = explode("; ", $editParts); 26 | 27 | $totalParts = count($editParts); 28 | $counter = 0; 29 | 30 | $firstField = true; 31 | 32 | foreach ($editParts as $part) { 33 | $part = trim($part); 34 | 35 | if ($part != "" && $part != ";") { 36 | 37 | list($user, $host) = explode("@", $part); 38 | 39 | $userSQL = $conn->query("SELECT * FROM `user` WHERE `User`='" . $user . "' AND `Host`='" . $host . "'"); 40 | $dbuserSQL = $conn->query("SELECT * FROM `db` WHERE `User`='" . $user . "' AND `Host`='" . $host . "'"); 41 | 42 | if ($conn->isResultSet($userSQL)) { 43 | 44 | $allPrivs = true; 45 | 46 | $dbShowList = array(); 47 | 48 | if ($conn->isResultSet($dbuserSQL)) { 49 | 50 | $accessLevel = "LIMITED"; 51 | 52 | while ($dbuserRow = $conn->fetchAssoc($dbuserSQL)) { 53 | $selectedPrivs = array(); 54 | 55 | $dbShowList[] = $dbuserRow['Db']; 56 | 57 | foreach ($dbuserRow as $key=>$value) { 58 | if (substr($key, -5) == "_priv" && $key != "Grant_priv" && $value == "N") { 59 | $allPrivs = false; 60 | } 61 | 62 | if ($value == "N") 63 | $selectedPrivs[$key] = $value; 64 | } 65 | 66 | if (isset($thePrivList)) { 67 | $thePrivList = array_merge($thePrivList, $selectedPrivs); 68 | } else { 69 | $thePrivList = $dbuserRow; 70 | } 71 | } 72 | } else { 73 | $accessLevel = "GLOBAL"; 74 | 75 | $userRow = $conn->fetchAssoc($userSQL); 76 | 77 | foreach ($userRow as $key=>$value) { 78 | if (substr($key, -5) == "_priv" && $key != "Grant_priv" && $value == "N") { 79 | $allPrivs = false; 80 | } 81 | } 82 | 83 | $thePrivList = $userRow; 84 | } 85 | 86 | echo '
'; 87 | echo '
'; 88 | echo ''; 89 | echo ''; 90 | 91 | ?> 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | listDatabases(); 104 | 105 | if ($conn->isResultSet($dbList)) { 106 | 107 | ?> 108 | 109 | 110 | 136 | 137 | 142 | 143 | 144 | 224 | 225 |
:
:
: 111 |
112 | 113 | 114 | 134 | 135 |
: 145 |
146 | 147 | 148 |
> 149 |
150 | 151 |
152 | 153 | 154 | 157 | 160 | 161 | 162 | 165 | 168 | 169 | 170 | 173 | 176 | 177 | 178 | 181 | 184 | 185 | 186 | 189 | 190 |
155 | 156 | 158 | 159 |
163 | 164 | 166 | 167 |
171 | 172 | 174 | 175 |
179 | 180 | 182 | 183 |
187 | 188 |
191 |
192 |
193 | 194 |
195 | 196 | 197 | 200 | 203 | 204 | 205 | 208 | 211 | 212 | 213 | 216 | 218 | 219 |
198 | 199 | 201 | 202 |
206 | 207 | 209 | 210 |
214 | 215 | 217 |
220 |
221 |
222 | 223 |
226 | 227 | 228 | 229 | 230 | 233 | 234 |
: 231 | 232 |
235 | 236 |
237 | " />   238 |
239 |
240 |
241 | 242 | -------------------------------------------------------------------------------- /src/home.php: -------------------------------------------------------------------------------- 1 | 13 | 14 | */ 15 | 16 | include "functions.php"; 17 | 18 | loginCheck(); 19 | 20 | ?> 21 | 22 | 23 | 26 | 27 | 28 | 142 | 143 | 144 | 147 | 148 | 149 | 158 | 159 | getAdapter() != "sqlite") { 162 | 163 | ?> 164 | 165 | 168 | 169 | 170 | 224 | 225 | 230 | 231 | 234 | 235 | 236 | 251 | 252 | 253 | 256 | 257 | 258 | 311 |
24 |

25 |
29 | 30 | getVersion(); 33 | 34 | if ($conn->getAdapter() == "mysql") { 35 | 36 | if (isset($_SESSION['SB_LOGIN_USER']) && $conn->getOptionValue("host")) { 37 | $message = sprintf(__("You are connected to MySQL %s with the user %s."), $dbVersion, $_SESSION['SB_LOGIN_USER'] . "@" . $conn->getOptionValue("host")); 38 | } 39 | 40 | } else if ($conn->getAdapter() == "sqlite") { 41 | $message = sprintf(__("You are connected to %s."), "SQLite " . $dbVersion); 42 | } 43 | 44 | echo "

" . $message . "

"; 45 | 46 | ?> 47 | 48 | 49 | 0) { 63 | $content = strip_tags($content); 64 | 65 | list($version, $notes) = explode("\n", $content, 2); 66 | 67 | ?> 68 | 69 | 72 | 83 | 84 | 90 | 91 | 94 | 116 | 117 | 118 | 121 | 138 | 139 |
70 | : 71 | 73 | ")) { 76 | echo '' . __("A new version of SQL Buddy is available!") . ' ' . __("Download") . ' »'; 77 | } else { 78 | echo __("There are no updates available") . "."; 79 | } 80 | 81 | ?> 82 |
92 | : 93 | 95 | 0) { 98 | 99 | echo ''; 111 | 112 | } 113 | 114 | ?> 115 |
119 | : 120 | 122 | 137 |
140 | 141 |
145 |

146 |
150 | 151 |
    152 |
  • 153 |
  • 154 |
  • 155 |
156 | 157 |
166 |

167 |
171 | 172 |
173 | 174 | 175 | 178 | 181 | 182 | "; 186 | echo ""; 189 | echo ""; 210 | echo ""; 211 | } 212 | 213 | ?> 214 | 215 | 216 | 219 | 220 |
176 | : 177 | 179 | 180 |
"; 187 | echo __("Charset") . ":"; 188 | echo ""; 190 | echo ""; 209 | echo "
217 | " /> 218 |
221 |
222 | 223 |
232 |

233 |
237 | 238 |

249 | 250 |
254 |

255 |
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 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 |
a
n
e
d
r
q
f
l
g
h
o
310 |
-------------------------------------------------------------------------------- /src/images/button.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deliciousbrains/sqlbuddy/8d684096dd5382bf4d85246430dde8afbfc539f3/src/images/button.png -------------------------------------------------------------------------------- /src/images/close.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deliciousbrains/sqlbuddy/8d684096dd5382bf4d85246430dde8afbfc539f3/src/images/close.png -------------------------------------------------------------------------------- /src/images/closeHover.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deliciousbrains/sqlbuddy/8d684096dd5382bf4d85246430dde8afbfc539f3/src/images/closeHover.png -------------------------------------------------------------------------------- /src/images/closedArrow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deliciousbrains/sqlbuddy/8d684096dd5382bf4d85246430dde8afbfc539f3/src/images/closedArrow.png -------------------------------------------------------------------------------- /src/images/goto.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deliciousbrains/sqlbuddy/8d684096dd5382bf4d85246430dde8afbfc539f3/src/images/goto.png -------------------------------------------------------------------------------- /src/images/info.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deliciousbrains/sqlbuddy/8d684096dd5382bf4d85246430dde8afbfc539f3/src/images/info.png -------------------------------------------------------------------------------- /src/images/infoHover.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deliciousbrains/sqlbuddy/8d684096dd5382bf4d85246430dde8afbfc539f3/src/images/infoHover.png -------------------------------------------------------------------------------- /src/images/initLoad.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deliciousbrains/sqlbuddy/8d684096dd5382bf4d85246430dde8afbfc539f3/src/images/initLoad.png -------------------------------------------------------------------------------- /src/images/loading.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deliciousbrains/sqlbuddy/8d684096dd5382bf4d85246430dde8afbfc539f3/src/images/loading.gif -------------------------------------------------------------------------------- /src/images/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deliciousbrains/sqlbuddy/8d684096dd5382bf4d85246430dde8afbfc539f3/src/images/logo.png -------------------------------------------------------------------------------- /src/images/openArrow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deliciousbrains/sqlbuddy/8d684096dd5382bf4d85246430dde8afbfc539f3/src/images/openArrow.png -------------------------------------------------------------------------------- /src/images/schemaHeader.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deliciousbrains/sqlbuddy/8d684096dd5382bf4d85246430dde8afbfc539f3/src/images/schemaHeader.png -------------------------------------------------------------------------------- /src/images/sortasc.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deliciousbrains/sqlbuddy/8d684096dd5382bf4d85246430dde8afbfc539f3/src/images/sortasc.gif -------------------------------------------------------------------------------- /src/images/sortdesc.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deliciousbrains/sqlbuddy/8d684096dd5382bf4d85246430dde8afbfc539f3/src/images/sortdesc.gif -------------------------------------------------------------------------------- /src/images/transparent.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deliciousbrains/sqlbuddy/8d684096dd5382bf4d85246430dde8afbfc539f3/src/images/transparent.png -------------------------------------------------------------------------------- /src/images/window-button.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deliciousbrains/sqlbuddy/8d684096dd5382bf4d85246430dde8afbfc539f3/src/images/window-button.png -------------------------------------------------------------------------------- /src/images/window-center.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deliciousbrains/sqlbuddy/8d684096dd5382bf4d85246430dde8afbfc539f3/src/images/window-center.png -------------------------------------------------------------------------------- /src/images/window-close.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deliciousbrains/sqlbuddy/8d684096dd5382bf4d85246430dde8afbfc539f3/src/images/window-close.png -------------------------------------------------------------------------------- /src/images/window-header-center.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deliciousbrains/sqlbuddy/8d684096dd5382bf4d85246430dde8afbfc539f3/src/images/window-header-center.png -------------------------------------------------------------------------------- /src/images/window-header-left.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deliciousbrains/sqlbuddy/8d684096dd5382bf4d85246430dde8afbfc539f3/src/images/window-header-left.png -------------------------------------------------------------------------------- /src/images/window-header-right.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deliciousbrains/sqlbuddy/8d684096dd5382bf4d85246430dde8afbfc539f3/src/images/window-header-right.png -------------------------------------------------------------------------------- /src/images/window-resize.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deliciousbrains/sqlbuddy/8d684096dd5382bf4d85246430dde8afbfc539f3/src/images/window-resize.png -------------------------------------------------------------------------------- /src/images/window-shadow-bottom-left.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deliciousbrains/sqlbuddy/8d684096dd5382bf4d85246430dde8afbfc539f3/src/images/window-shadow-bottom-left.png -------------------------------------------------------------------------------- /src/images/window-shadow-bottom-right.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deliciousbrains/sqlbuddy/8d684096dd5382bf4d85246430dde8afbfc539f3/src/images/window-shadow-bottom-right.png -------------------------------------------------------------------------------- /src/images/window-shadow-bottom.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deliciousbrains/sqlbuddy/8d684096dd5382bf4d85246430dde8afbfc539f3/src/images/window-shadow-bottom.png -------------------------------------------------------------------------------- /src/images/window-shadow-left.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deliciousbrains/sqlbuddy/8d684096dd5382bf4d85246430dde8afbfc539f3/src/images/window-shadow-left.png -------------------------------------------------------------------------------- /src/images/window-shadow-right.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deliciousbrains/sqlbuddy/8d684096dd5382bf4d85246430dde8afbfc539f3/src/images/window-shadow-right.png -------------------------------------------------------------------------------- /src/import.php: -------------------------------------------------------------------------------- 1 | 13 | 14 | */ 15 | 16 | include "functions.php"; 17 | 18 | loginCheck(); 19 | 20 | ?> 21 | 22 |
23 | 24 | 25 | 26 |

27 | 28 |
29 | 30 | 34 | 35 | 36 | 37 | 41 | 42 | 43 | 46 | 47 | 51 | 52 | 53 | 57 | 58 | 62 |
.
: 44 | 45 |
: 54 |
55 | 56 |
63 | 64 |
65 | 66 | 67 | 68 | 69 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 |
" />
83 | 84 |
85 | 86 |
87 | 88 | -------------------------------------------------------------------------------- /src/includes/browse.php: -------------------------------------------------------------------------------- 1 | 13 | 14 | */ 15 | 16 | $totalRows = 0; 17 | $insertCount = 0; 18 | $queryTime = 0; 19 | 20 | $perPage = (isset($sbconfig) && array_key_exists("RowsPerPage", $sbconfig)) ? $sbconfig['RowsPerPage'] : 100; 21 | 22 | $displayLimit = 1000; 23 | 24 | $query = trim($query); 25 | 26 | if ($query) { 27 | 28 | if (!isset($queryTable)) { 29 | $querySplit = splitQueryText($query); 30 | } else { 31 | $querySplit[] = $query; 32 | } 33 | 34 | foreach ($querySplit as $q) { 35 | $q = trim($q, "\n"); 36 | if ($q != "") { 37 | if (isset($queryTable)) { 38 | $totalRows = $conn->tableRowCount($queryTable); 39 | 40 | if ($start > $totalRows) { 41 | $start = 0; 42 | } 43 | 44 | $q = "$q $sort LIMIT $start, $perPage"; 45 | } 46 | 47 | $queryStartTime = microtime_float(); 48 | $dataSql = $conn->query($q) or ($dbError[] = $conn->error()); 49 | $queryFinishTime = microtime_float(); 50 | $queryTime += round($queryFinishTime - $queryStartTime, 4); 51 | 52 | if ($conn->affectedRows($dataSql)) { 53 | $insertCount += (int)($conn->affectedRows($dataSql)); 54 | } 55 | } 56 | } 57 | 58 | if (!isset($queryTable)) { 59 | $totalRows = (int)($conn->rowCount($dataSql)); 60 | 61 | // running rowCount on PDO resets the result set 62 | // so we need to run the query again 63 | if ($conn->getMethod() == "pdo") { 64 | $dataSql = $conn->query($q); 65 | } 66 | } 67 | 68 | } 69 | 70 | //for the browse tab 71 | if (isset($queryTable) && $conn->getAdapter() == "sqlite") { 72 | $structure = $conn->describeTable($queryTable); 73 | 74 | if (sizeof($structure) > 0) { 75 | foreach ($structure as $column) { 76 | if (strpos($column[1], "primary key") > 0) { 77 | $primaryKeys[] = $column[0]; 78 | } 79 | } 80 | } 81 | } else if (isset($queryTable) && $conn->getAdapter() == "mysql") { 82 | $structureSql = $conn->describeTable($queryTable); 83 | 84 | if ($conn->isResultSet($structureSql)) { 85 | while ($structureRow = $conn->fetchAssoc($structureSql)) { 86 | $explosion = explode("(", $structureRow['Type'], 2); 87 | 88 | $tableTypes[] = $explosion[0]; 89 | 90 | if ($structureRow['Key'] == "PRI") { 91 | $primaryKeys[] = $structureRow['Field']; 92 | } 93 | } 94 | } 95 | } 96 | 97 | echo '
'; 98 | 99 | if (isset($dbError)) { 100 | echo '
' . __("The following errors were reported") . ':'; 101 | foreach ($dbError as $error) { 102 | echo $error . "
"; 103 | } 104 | echo '
'; 105 | } else { 106 | 107 | if (isset($totalRows) && $totalRows > 0) { 108 | 109 | if (isset($queryTable)) { 110 | 111 | echo ''; 112 | echo ''; 113 | echo ''; 127 | 128 | echo ''; 177 | echo ''; 178 | echo '
'; 114 | 115 | if (isset($primaryKeys) && count($primaryKeys)) { 116 | 117 | echo __("Select") . ':  ' . __("All") . '  ' . __("None") . ''; 118 | echo '     ' . __("With selected") . ':  ' . __("Edit") . '  ' . __("Delete") . ''; 119 | 120 | echo '       ' . __("Refresh") . ''; 121 | 122 | } else { 123 | echo '[' . __("No primary key defined") . ']'; 124 | } 125 | 126 | echo ''; 129 | 130 | $totalPages = ceil($totalRows / $perPage); 131 | $currentPage = floor($start / $perPage) + 1; 132 | 133 | if ($currentPage > 1) { 134 | echo '' . __("First") . ''; 135 | echo '' . __("Prev") . ''; 136 | } 137 | 138 | echo ''; 139 | 140 | if ($currentPage == 1) { 141 | $startPage = 1; 142 | $finishPage = 3; 143 | 144 | if ($finishPage > $totalPages) 145 | $finishPage = $totalPages; 146 | 147 | } else if ($currentPage == $totalPages) { 148 | $startPage = $totalPages - 2; 149 | $finishPage = $totalPages; 150 | 151 | if ($startPage < 1) 152 | $startPage = 1; 153 | } else { 154 | $startPage = $currentPage - 1; 155 | $finishPage = $currentPage + 1; 156 | } 157 | 158 | if ($startPage != $finishPage) { 159 | for ($bnav=$startPage; $bnav<=$finishPage; $bnav++) { 160 | echo '' . number_format($bnav) . ''; 166 | } 167 | } 168 | 169 | echo ''; 170 | 171 | if ($currentPage < $totalPages) { 172 | echo '' . __("Next") . ''; 173 | echo '' . __("Last") . ''; 174 | } 175 | 176 | echo '
'; 179 | 180 | } else { 181 | echo ''; 182 | echo ''; 183 | echo ''; 191 | echo ''; 192 | echo '
'; 184 | 185 | printf(__p("Your query returned %d result.", "Your query returned %d results.", $totalRows), $totalRows); 186 | echo " " . sprintf(__("(%.4f seconds)"), $queryTime); 187 | 188 | if ($totalRows > $displayLimit) 189 | echo ' (' . sprintf(__("Note: To avoid crashing your browser, only the first %d results have been displayed"), $displayLimit) . '.)'; 190 | echo '
'; 193 | } 194 | 195 | echo '
'; 196 | 197 | if (isset($primaryKeys) && count($primaryKeys)) { 198 | echo '
 
'; 199 | } 200 | 201 | echo '
'; 207 | 208 | echo '
'; 209 | echo ''; 210 | echo ''; 211 | 212 | if ($conn->isResultSet($dataSql)) { 213 | $dataRow = $conn->fetchAssoc($dataSql); 214 | $g = 0; 215 | $numFields = 0; 216 | 217 | foreach ($dataRow as $key=>$value) { 218 | 219 | if ((isset($sortKey) && $sortKey == $key) && (isset($sortDir) && $sortDir == "ASC")) { 220 | $outputDir = "DESC"; 221 | } elseif (isset($sortKey) && $sortKey == $key) { 222 | $outputDir = "ASC"; 223 | } elseif (isset($sortDir) && $sortDir) { 224 | $outputDir = $sortDir; 225 | } else { 226 | $outputDir = "ASC"; 227 | } 228 | echo ''; 260 | echo ''; 261 | $numFields++; 262 | } 263 | echo ''; 264 | echo ''; 265 | echo '
'; 247 | 248 | if ((isset($sortKey) && $sortKey == $key) && (isset($sortDir) && $sortDir == "DESC")) { 249 | echo '
' . $key . '
'; 250 | } elseif ((isset($sortKey) && $sortKey == $key) && (isset($sortDir) && $sortDir == "ASC")) { 251 | echo '
' . $key . '
'; 252 | } else { 253 | echo $key; 254 | } 255 | 256 | $fieldList[] = $key; 257 | 258 | echo '
'; 259 | echo '
 
'; 266 | 267 | } 268 | 269 | echo '
'; 270 | echo '
'; 271 | 272 | $dataSql = $conn->query($q); 273 | 274 | $queryBuilder = ""; 275 | 276 | if (isset($primaryKeys) && count($primaryKeys) > 0) { 277 | 278 | echo '
'; 279 | 280 | $m = 0; 281 | 282 | while (($dataRow = $conn->fetchAssoc($dataSql)) && ($m < $displayLimit)) { 283 | 284 | $queryBuilder = "WHERE "; 285 | foreach ($primaryKeys as $primary) { 286 | if ($conn->getAdapter() == "sqlite") { 287 | $queryBuilder .= "" . $primary . "='" . $dataRow[$primary] . "' AND "; 288 | } else { 289 | $queryBuilder .= "`" . $primary . "`='" . $dataRow[$primary] . "' AND "; 290 | } 291 | } 292 | $queryBuilder = substr($queryBuilder, 0, -5); 293 | 294 | if ($conn->getAdapter() == "mysql") { 295 | $queryBuilder .= " LIMIT 1"; 296 | } 297 | 298 | echo '
'; 306 | echo '
'; 307 | echo '
'; 308 | echo '
'; 309 | 310 | $m++; 311 | } 312 | 313 | echo '
'; 314 | 315 | $dataSql = $conn->query($q); 316 | 317 | } 318 | 319 | if (isset($primaryKeys) && count($primaryKeys)) 320 | echo '
'; 321 | else 322 | echo '
'; 323 | 324 | $m = 0; 325 | 326 | while (($dataRow = $conn->fetchArray($dataSql)) && ($m < $displayLimit)) { 327 | 328 | echo ''; 336 | echo ''; 337 | echo ''; 365 | echo ''; 366 | echo '
'; 338 | 339 | echo ''; 340 | echo ''; 341 | 342 | for ($i=0; $i<$numFields; $i++) { 343 | echo ''; 361 | } 362 | echo ''; 363 | echo '
'; 351 | 352 | if (isset($tableTypes) && in_array($tableTypes[$i], $binaryDTs)) { 353 | echo '(' . __("binary data") . ')'; 354 | } else if (is_numeric($dataRow[$i]) && stristr($fieldList[$i], "Date") !== false && strlen($dataRow[$i]) > 7 && strlen($dataRow[$i]) < 14) { 355 | echo '' . formatForOutput($dataRow[$i]) . ''; 356 | } else { 357 | echo formatForOutput($dataRow[$i]); 358 | } 359 | 360 | echo '
'; 364 | echo '
'; 367 | 368 | $m++; 369 | } 370 | echo '
'; 371 | echo '
'; 372 | 373 | ?> 374 | 375 | 378 | 379 | ' . sprintf(__("Your query affected %d rows."), $insertCount) . '
'; 383 | 384 | if (isset($queryTable) && $queryTable) { 385 | ?> 386 | 387 | 392 | 393 | ' . __("Your query did not return any results.") . " " . sprintf(__("(%.4f seconds)"), $queryTime) . '
'; 396 | } 397 | } 398 | } 399 | 400 | echo ''; 401 | 402 | ?> -------------------------------------------------------------------------------- /src/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 | ?> -------------------------------------------------------------------------------- /src/includes/class/Sql-php4.php: -------------------------------------------------------------------------------- 1 | 13 | 14 | */ 15 | 16 | class SQL { 17 | 18 | var $adapter = ""; 19 | var $method = ""; 20 | var $version = ""; 21 | var $conn = ""; 22 | var $options = ""; 23 | var $errorMessage = ""; 24 | var $db = ""; 25 | 26 | function SQL($connString, $user = "", $pass = "") { 27 | list($this->adapter, $options) = explode(":", $connString, 2); 28 | 29 | if ($this->adapter != "sqlite") { 30 | $this->adapter = "mysql"; 31 | } 32 | 33 | $optionsList = explode(";", $options); 34 | 35 | foreach ($optionsList as $option) { 36 | list($a, $b) = explode("=", $option); 37 | $opt[$a] = $b; 38 | } 39 | 40 | $this->options = $opt; 41 | $database = (array_key_exists("database", $opt)) ? $opt['database'] : ""; 42 | 43 | if ($this->adapter == "sqlite") { 44 | $this->method = "sqlite"; 45 | $this->conn = sqlite_open($database, 0666, $sqliteError); 46 | } else { 47 | $this->method = "mysql"; 48 | $host = (array_key_exists("host", $opt)) ? $opt['host'] : ""; 49 | $this->conn = @mysql_connect($host, $user, $pass); 50 | } 51 | 52 | if ($this->conn && $this->adapter == "mysql") { 53 | $this->query("SET NAMES 'utf8'"); 54 | } 55 | } 56 | 57 | function isConnected() { 58 | return ($this->conn !== false); 59 | } 60 | 61 | function disconnect() { 62 | if ($this->conn) { 63 | if ($this->method == "mysql") { 64 | mysql_close($this->conn); 65 | $this->conn = null; 66 | } else if ($this->method == "sqlite") { 67 | sqlite_close($this->conn); 68 | $this->conn = null; 69 | } 70 | } 71 | } 72 | 73 | function getAdapter() { 74 | return $this->adapter; 75 | } 76 | 77 | function getMethod() { 78 | return $this->method; 79 | } 80 | 81 | function getOptionValue($optKey) { 82 | if (array_key_exists($optKey, $this->options)) { 83 | return $this->options[$optKey]; 84 | } else { 85 | return false; 86 | } 87 | } 88 | 89 | function selectDB($db) { 90 | if ($this->conn) { 91 | 92 | $this->db = $db; 93 | 94 | if ($this->method == "mysql") { 95 | return (mysql_select_db($db)); 96 | } else { 97 | return true; 98 | } 99 | } else { 100 | return false; 101 | } 102 | } 103 | 104 | function query($queryText) { 105 | if ($this->conn) { 106 | if ($this->method == "mysql") { 107 | $queryResult = @mysql_query($queryText, $this->conn); 108 | 109 | if (!$queryResult) { 110 | $this->errorMessage = mysql_error(); 111 | } 112 | 113 | return $queryResult; 114 | } else if ($this->method == "sqlite") { 115 | $queryResult = sqlite_query($this->conn, $queryText); 116 | 117 | if (!$queryResult) { 118 | $this->errorMessage = sqlite_error_string(sqlite_last_error($this->conn)); 119 | } 120 | 121 | return $queryResult; 122 | } 123 | } else { 124 | return false; 125 | } 126 | } 127 | 128 | function rowCount($resultSet) { 129 | if ($this->conn) { 130 | if ($this->method == "mysql") { 131 | return @mysql_num_rows($resultSet); 132 | } else if ($this->method == "sqlite") { 133 | return @sqlite_num_rows($resultSet); 134 | } 135 | } 136 | } 137 | 138 | function isResultSet($resultSet) { 139 | if ($this->conn) { 140 | return ($this->rowCount($resultSet) > 0); 141 | } 142 | } 143 | 144 | function fetchArray($resultSet) { 145 | if (!$resultSet) 146 | return false; 147 | 148 | if ($this->conn) { 149 | if ($this->method == "mysql") { 150 | return mysql_fetch_row($resultSet); 151 | } else if ($this->method == "sqlite") { 152 | return sqlite_fetch_array($resultSet, SQLITE_NUM); 153 | } 154 | } 155 | } 156 | 157 | function fetchAssoc($resultSet) { 158 | if (!$resultSet) 159 | return false; 160 | 161 | if ($this->conn) { 162 | if ($this->method == "mysql") { 163 | return mysql_fetch_assoc($resultSet); 164 | } else if ($this->method == "sqlite") { 165 | return sqlite_fetch_array($resultSet, SQLITE_ASSOC); 166 | } 167 | } 168 | } 169 | 170 | function affectedRows($resultSet) { 171 | if (!$resultSet) 172 | return false; 173 | 174 | if ($this->conn) { 175 | if ($this->method == "mysql") { 176 | return @mysql_affected_rows($resultSet); 177 | } else if ($this->method == "sqlite") { 178 | return sqlite_changes($resultSet); 179 | } 180 | } 181 | } 182 | 183 | function result($resultSet, $targetRow, $targetColumn = "") { 184 | if (!$resultSet) 185 | return false; 186 | 187 | if ($this->conn) { 188 | if ($this->method == "mysql") { 189 | return mysql_result($resultSet, $targetRow, $targetColumn); 190 | } else if ($this->method == "sqlite") { 191 | return sqlite_column($resultSet, $targetColumn); 192 | } 193 | } 194 | } 195 | 196 | function listDatabases() { 197 | if ($this->conn) { 198 | if ($this->adapter == "mysql") { 199 | return $this->query("SHOW DATABASES"); 200 | } else if ($this->adapter == "sqlite") { 201 | $database = (array_key_exists("database", $this->options)) ? $this->options['database'] : ""; 202 | return $database; 203 | } 204 | } 205 | } 206 | 207 | function listTables() { 208 | if ($this->conn) { 209 | if ($this->adapter == "mysql") { 210 | return $this->query("SHOW TABLES"); 211 | } else if ($this->adapter == "sqlite") { 212 | return $this->query("SELECT name FROM sqlite_master WHERE type = 'table' ORDER BY name"); 213 | } 214 | } 215 | } 216 | 217 | function hasCharsetSupport() 218 | { 219 | if ($this->conn) { 220 | if ($this->adapter == "mysql" && version_compare($this->getVersion(), "4.1", ">")) { 221 | return true; 222 | } else { 223 | return false; 224 | } 225 | } 226 | } 227 | 228 | function listCharset() { 229 | if ($this->conn) { 230 | if ($this->adapter == "mysql") { 231 | return $this->query("SHOW CHARACTER SET"); 232 | } else if ($this->adapter == "sqlite") { 233 | return ""; 234 | } 235 | } 236 | } 237 | 238 | function listCollation() { 239 | if ($this->conn) { 240 | if ($this->adapter == "mysql") { 241 | return $this->query("SHOW COLLATION"); 242 | } else if ($this->adapter == "sqlite") { 243 | return ""; 244 | } 245 | } 246 | } 247 | 248 | function insertId($resultSet = null) { 249 | if ($this->conn) { 250 | if ($this->method == "mysql") { 251 | return mysql_insert_id($resultSet); 252 | } else if ($this->method == "sqlite") { 253 | return sqlite_last_insert_rowid($resultSet); 254 | } 255 | } 256 | } 257 | 258 | function escapeString($toEscape) { 259 | if ($this->conn) { 260 | if ($this->adapter == "mysql") { 261 | return mysql_real_escape_string($toEscape); 262 | } else if ($this->adapter == "sqlite") { 263 | return sqlite_escape_string($toEscape); 264 | } 265 | } 266 | } 267 | 268 | function getVersion() { 269 | if ($this->conn) { 270 | // cache 271 | if ($this->version) { 272 | return $this->version; 273 | } 274 | 275 | if ($this->adapter == "mysql") { 276 | $verSql = mysql_get_server_info(); 277 | $version = explode("-", $verSql); 278 | $this->version = $version[0]; 279 | return $this->version; 280 | } else if ($this->adapter == "sqlite") { 281 | $this->version = sqlite_libversion(); 282 | return $this->version; 283 | } 284 | } 285 | 286 | } 287 | 288 | // returns the number of rows in a table 289 | function tableRowCount($table) { 290 | if ($this->conn) { 291 | if ($this->adapter == "mysql") { 292 | $countSql = $this->query("SELECT COUNT(*) AS `RowCount` FROM `" . $table . "`"); 293 | $count = (int)($this->result($countSql, 0, "RowCount")); 294 | return $count; 295 | } else if ($this->adapter == "sqlite") { 296 | $countSql = $this->query("SELECT COUNT(*) AS 'RowCount' FROM '" . $table . "'"); 297 | $count = (int)($this->result($countSql, 0, "RowCount")); 298 | return $count; 299 | } 300 | } 301 | } 302 | 303 | // gets column info for a table 304 | function describeTable($table) { 305 | if ($this->conn) { 306 | if ($this->adapter == "mysql") { 307 | return $this->query("DESCRIBE `" . $table . "`"); 308 | } else if ($this->adapter == "sqlite") { 309 | $columnSql = $this->query("SELECT sql FROM sqlite_master where tbl_name = '" . $table . "'"); 310 | $columnInfo = $this->result($columnSql, 0, "sql"); 311 | $columnStart = strpos($columnInfo, '('); 312 | $columns = substr($columnInfo, $columnStart+1, -1); 313 | $columns = split(',[^0-9]', $columns); 314 | 315 | $columnList = array(); 316 | 317 | foreach ($columns as $column) { 318 | $column = trim($column); 319 | $columnSplit = explode(" ", $column, 2); 320 | $columnName = $columnSplit[0]; 321 | $columnType = (sizeof($columnSplit) > 1) ? $columnSplit[1] : ""; 322 | $columnList[] = array($columnName, $columnType); 323 | } 324 | 325 | return $columnList; 326 | } 327 | } 328 | } 329 | 330 | /* 331 | Return names, row counts etc for every database, table and view in a JSON string 332 | */ 333 | function getMetadata() { 334 | $output = ''; 335 | if ($this->conn) { 336 | if ($this->adapter == "mysql" && version_compare($this->getVersion(), "5.0.0", ">=")) { 337 | $this->selectDB("information_schema"); 338 | $schemaSql = $this->query("SELECT `SCHEMA_NAME` FROM `SCHEMATA` ORDER BY `SCHEMA_NAME`"); 339 | if ($this->rowCount($schemaSql)) { 340 | while ($schema = $this->fetchAssoc($schemaSql)) { 341 | $output .= '{"name": "' . $schema['SCHEMA_NAME'] . '"'; 342 | // other interesting columns: TABLE_TYPE, ENGINE, TABLE_COLUMN and many more 343 | $tableSql = $this->query("SELECT `TABLE_NAME`, `TABLE_ROWS` FROM `TABLES` WHERE `TABLE_SCHEMA`='" . $schema['SCHEMA_NAME'] . "' ORDER BY `TABLE_NAME`"); 344 | if ($this->rowCount($tableSql)) { 345 | $output .= ',"items": ['; 346 | while ($table = $this->fetchAssoc($tableSql)) { 347 | 348 | if ($schema['SCHEMA_NAME'] == "information_schema") { 349 | $countSql = $this->query("SELECT COUNT(*) AS `RowCount` FROM `" . $table['TABLE_NAME'] . "`"); 350 | $rowCount = (int)($this->result($countSql, 0, "RowCount")); 351 | } else { 352 | $rowCount = (int)($table['TABLE_ROWS']); 353 | } 354 | 355 | $output .= '{"name":"' . $table['TABLE_NAME'] . '","rowcount":' . $rowCount . '},'; 356 | } 357 | 358 | if (substr($output, -1) == ",") 359 | $output = substr($output, 0, -1); 360 | 361 | $output .= ']'; 362 | } 363 | $output .= '},'; 364 | } 365 | $output = substr($output, 0, -1); 366 | } 367 | } else if ($this->adapter == "mysql") { 368 | $schemaSql = $this->listDatabases(); 369 | 370 | if ($this->rowCount($schemaSql)) { 371 | while ($schema = $this->fetchArray($schemaSql)) { 372 | $output .= '{"name": "' . $schema[0] . '"'; 373 | 374 | $this->selectDB($schema[0]); 375 | $tableSql = $this->listTables(); 376 | 377 | if ($this->rowCount($tableSql)) { 378 | $output .= ',"items": ['; 379 | while ($table = $this->fetchArray($tableSql)) { 380 | $countSql = $this->query("SELECT COUNT(*) AS `RowCount` FROM `" . $table[0] . "`"); 381 | $rowCount = (int)($this->result($countSql, 0, "RowCount")); 382 | $output .= '{"name":"' . $table[0] . '","rowcount":' . $rowCount . '},'; 383 | } 384 | 385 | if (substr($output, -1) == ",") 386 | $output = substr($output, 0, -1); 387 | 388 | $output .= ']'; 389 | } 390 | $output .= '},'; 391 | } 392 | $output = substr($output, 0, -1); 393 | } 394 | } else if ($this->adapter == "sqlite") { 395 | $database = (array_key_exists("database", $this->options)) ? $this->options['database'] : ""; 396 | 397 | $output .= '{"name": "' . $database . '"'; 398 | 399 | $tableSql = $this->listTables(); 400 | 401 | if ($this->rowCount($tableSql)) { 402 | $output .= ',"items": ['; 403 | while ($tableRow = $this->fetchArray($tableSql)) { 404 | $countSql = $this->query("SELECT COUNT(*) AS 'RowCount' FROM '" . $tableRow[0] . "'"); 405 | $rowCount = (int)($this->result($countSql, 0, "RowCount")); 406 | $output .= '{"name":"' . $tableRow[0] . '","rowcount":' . $rowCount . '},'; 407 | } 408 | 409 | if (substr($output, -1) == ",") 410 | $output = substr($output, 0, -1); 411 | 412 | $output .= ']'; 413 | } 414 | $output .= '}'; 415 | } 416 | } 417 | return $output; 418 | } 419 | 420 | function error() { 421 | return $this->errorMessage; 422 | } 423 | 424 | } -------------------------------------------------------------------------------- /src/includes/class/Sql.php: -------------------------------------------------------------------------------- 1 | 13 | 14 | */ 15 | 16 | # There is no good corresponding mysql_result function in mysqli. mysql_result is approximated here. 17 | function mysqli_result($res, $row, $field=0) { 18 | $res->data_seek($row); 19 | $datarow = $res->fetch_array(); 20 | return $datarow[$field]; 21 | } 22 | 23 | class SQL { 24 | 25 | var $adapter = ""; 26 | var $method = ""; 27 | var $version = ""; 28 | var $conn = ""; 29 | var $options = ""; 30 | var $errorMessage = ""; 31 | var $db = ""; 32 | 33 | function __construct($connString, $user = "", $pass = "") { 34 | list($this->adapter, $options) = explode(":", $connString, 2); 35 | 36 | if ($this->adapter != "sqlite") { 37 | $this->adapter = "mysql"; 38 | } 39 | 40 | $optionsList = explode(";", $options); 41 | 42 | foreach ($optionsList as $option) { 43 | list($a, $b) = explode("=", $option); 44 | $opt[$a] = $b; 45 | } 46 | 47 | $this->options = $opt; 48 | $database = (array_key_exists("database", $opt)) ? $opt['database'] : ""; 49 | 50 | if ($this->adapter == "sqlite" && substr(sqlite_libversion(), 0, 1) == "3" && class_exists("PDO") && in_array("sqlite", PDO::getAvailableDrivers())) { 51 | $this->method = "pdo"; 52 | 53 | try 54 | { 55 | $this->conn = new PDO("sqlite:" . $database, null, null, array(PDO::ATTR_PERSISTENT => true)); 56 | } 57 | catch (PDOException $error) { 58 | $this->conn = false; 59 | $this->errorMessage = $error->getMessage(); 60 | } 61 | } else if ($this->adapter == "sqlite" && substr(sqlite_libversion(), 0, 1) == "2" && class_exists("PDO") && in_array("sqlite2", PDO::getAvailableDrivers())) { 62 | $this->method = "pdo"; 63 | 64 | try 65 | { 66 | $this->conn = new PDO("sqlite2:" . $database, null, null, array(PDO::ATTR_PERSISTENT => true)); 67 | } 68 | catch (PDOException $error) { 69 | $this->conn = false; 70 | $this->errorMessage = $error->getMessage(); 71 | } 72 | } else if ($this->adapter == "sqlite") { 73 | $this->method = "sqlite"; 74 | $this->conn = sqlite_open($database, 0666, $sqliteError); 75 | } else { 76 | $this->method = "mysql"; 77 | $host = (array_key_exists("host", $opt)) ? $opt['host'] : ""; 78 | $this->conn = @mysqli_connect($host, $user, $pass); 79 | } 80 | 81 | if ($this->conn && $this->method == "pdo") { 82 | $this->conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT); 83 | } 84 | 85 | if ($this->conn && $this->adapter == "mysql") { 86 | $this->query("SET NAMES 'utf8'"); 87 | } 88 | 89 | if ($this->conn && $database) { 90 | $this->db = $database; 91 | } 92 | } 93 | 94 | function isConnected() { 95 | return ($this->conn !== false); 96 | } 97 | 98 | function disconnect() { 99 | if ($this->conn) { 100 | if ($this->method == "pdo") { 101 | $this->conn = null; 102 | } else if ($this->method == "mysql") { 103 | mysqli_close($this->conn); 104 | $this->conn = null; 105 | } else if ($this->method == "sqlite") { 106 | sqlite_close($this->conn); 107 | $this->conn = null; 108 | } 109 | } 110 | } 111 | 112 | function getAdapter() { 113 | return $this->adapter; 114 | } 115 | 116 | function getMethod() { 117 | return $this->method; 118 | } 119 | 120 | function getOptionValue($optKey) { 121 | if (array_key_exists($optKey, $this->options)) { 122 | return $this->options[$optKey]; 123 | } else { 124 | return false; 125 | } 126 | } 127 | 128 | function selectDB($db) { 129 | if ($this->conn) { 130 | if ($this->method == "mysql") { 131 | $this->db = $db; 132 | return (mysqli_select_db($this->conn, $db)); 133 | } else { 134 | return true; 135 | } 136 | } else { 137 | return false; 138 | } 139 | } 140 | 141 | function query($queryText) { 142 | if ($this->conn) { 143 | if ($this->method == "pdo") { 144 | $queryResult = $this->conn->prepare($queryText); 145 | 146 | if ($queryResult) 147 | $queryResult->execute(); 148 | 149 | if (!$queryResult) { 150 | $errorInfo = $this->conn->errorInfo(); 151 | $this->errorMessage = $errorInfo[2]; 152 | } 153 | 154 | return $queryResult; 155 | } else if ($this->method == "mysql") { 156 | $queryResult = @mysqli_query($this->conn, $queryText); 157 | 158 | if (!$queryResult) { 159 | $this->errorMessage = mysqli_error($this->conn); 160 | } 161 | 162 | return $queryResult; 163 | } else if ($this->method == "sqlite") { 164 | $queryResult = sqlite_query($this->conn, $queryText); 165 | 166 | if (!$queryResult) { 167 | $this->errorMessage = sqlite_error_string(sqlite_last_error($this->conn)); 168 | } 169 | 170 | return $queryResult; 171 | } 172 | } else { 173 | return false; 174 | } 175 | } 176 | 177 | // Be careful using this function - when used with pdo, the pointer is moved 178 | // to the end of the result set and the query needs to be rerun. Unless you 179 | // actually need a count of the rows, use the isResultSet() function instead 180 | function rowCount($resultSet) { 181 | if (!$resultSet) 182 | return false; 183 | 184 | if ($this->conn) { 185 | if ($this->method == "pdo") { 186 | return count($resultSet->fetchAll()); 187 | } else if ($this->method == "mysql") { 188 | return @mysqli_num_rows($resultSet); 189 | } else if ($this->method == "sqlite") { 190 | return @sqlite_num_rows($resultSet); 191 | } 192 | } 193 | } 194 | 195 | function isResultSet($resultSet) { 196 | if ($this->conn) { 197 | if ($this->method == "pdo") { 198 | return ($resultSet == true); 199 | } else { 200 | return ($this->rowCount($resultSet) > 0); 201 | } 202 | } 203 | } 204 | 205 | function fetchArray($resultSet) { 206 | if (!$resultSet) 207 | return false; 208 | 209 | if ($this->conn) { 210 | if ($this->method == "pdo") { 211 | return $resultSet->fetch(PDO::FETCH_NUM); 212 | } else if ($this->method == "mysql") { 213 | return mysqli_fetch_row($resultSet); 214 | } else if ($this->method == "sqlite") { 215 | return sqlite_fetch_array($resultSet, SQLITE_NUM); 216 | } 217 | } 218 | } 219 | 220 | function fetchAssoc($resultSet) { 221 | if (!$resultSet) 222 | return false; 223 | 224 | if ($this->conn) { 225 | if ($this->method == "pdo") { 226 | return $resultSet->fetch(PDO::FETCH_ASSOC); 227 | } else if ($this->method == "mysql") { 228 | return mysqli_fetch_assoc($resultSet); 229 | } else if ($this->method == "sqlite") { 230 | return sqlite_fetch_array($resultSet, SQLITE_ASSOC); 231 | } 232 | } 233 | } 234 | 235 | function affectedRows($resultSet) { 236 | if (!$resultSet) 237 | return false; 238 | 239 | if ($this->conn) { 240 | if ($this->method == "pdo") { 241 | return $resultSet->rowCount(); 242 | } else if ($this->method == "mysql") { 243 | # return @mysqli_affected_rows($resultSet); 244 | return @mysqli_affected_rows($this->conn); 245 | } else if ($this->method == "sqlite") { 246 | return sqlite_changes($resultSet); 247 | } 248 | } 249 | } 250 | 251 | function result($resultSet, $targetRow, $targetColumn = "") { 252 | if (!$resultSet) 253 | return false; 254 | 255 | if ($this->conn) { 256 | if ($this->method == "pdo") { 257 | if ($targetColumn) { 258 | $resultRow = $resultSet->fetch(PDO::FETCH_ASSOC, PDO::FETCH_ORI_ABS, $targetRow); 259 | return $resultRow[$targetColumn]; 260 | } else { 261 | $resultRow = $resultSet->fetch(PDO::FETCH_NUM, PDO::FETCH_ORI_ABS, $targetRow); 262 | return $resultRow[0]; 263 | } 264 | } else if ($this->method == "mysql") { 265 | return mysqli_result($resultSet, $targetRow, $targetColumn); 266 | } else if ($this->method == "sqlite") { 267 | return sqlite_column($resultSet, $targetColumn); 268 | } 269 | } 270 | } 271 | 272 | function listDatabases() { 273 | if ($this->conn) { 274 | if ($this->adapter == "mysql") { 275 | return $this->query("SHOW DATABASES"); 276 | } else if ($this->adapter == "sqlite") { 277 | return $this->db; 278 | } 279 | } 280 | } 281 | 282 | function listTables() { 283 | if ($this->conn) { 284 | if ($this->adapter == "mysql") { 285 | return $this->query("SHOW TABLES"); 286 | } else if ($this->adapter == "sqlite") { 287 | return $this->query("SELECT name FROM sqlite_master WHERE type = 'table' ORDER BY name"); 288 | } 289 | } 290 | } 291 | 292 | function hasCharsetSupport() 293 | { 294 | if ($this->conn) { 295 | if ($this->adapter == "mysql" && version_compare($this->getVersion(), "4.1", ">")) { 296 | return true; 297 | } else { 298 | return false; 299 | } 300 | } 301 | } 302 | 303 | function listCharset() { 304 | if ($this->conn) { 305 | if ($this->adapter == "mysql") { 306 | return $this->query("SHOW CHARACTER SET"); 307 | } else if ($this->adapter == "sqlite") { 308 | return ""; 309 | } 310 | } 311 | } 312 | 313 | function listCollation() { 314 | if ($this->conn) { 315 | if ($this->adapter == "mysql") { 316 | return $this->query("SHOW COLLATION"); 317 | } else if ($this->adapter == "sqlite") { 318 | return ""; 319 | } 320 | } 321 | } 322 | 323 | function insertId() { 324 | if ($this->conn) { 325 | if ($this->method == "pdo") { 326 | return $this->conn->lastInsertId(); 327 | } else if ($this->method == "mysql") { 328 | return @mysqli_insert_id($this->conn); 329 | } else if ($this->method == "sqlite") { 330 | return sqlite_last_insert_rowid($this-conn); 331 | } 332 | } 333 | } 334 | 335 | function escapeString($toEscape) { 336 | if ($this->conn) { 337 | if ($this->method == "pdo") { 338 | $toEscape = $this->conn->quote($toEscape); 339 | $toEscape = substr($toEscape, 1, -1); 340 | return $toEscape; 341 | } else if ($this->adapter == "mysql") { 342 | return mysqli_real_escape_string($this->conn, $toEscape); 343 | } else if ($this->adapter == "sqlite") { 344 | return sqlite_escape_string($toEscape); 345 | } 346 | } 347 | } 348 | 349 | function getVersion() { 350 | if ($this->conn) { 351 | // cache 352 | if ($this->version) { 353 | return $this->version; 354 | } 355 | 356 | if ($this->adapter == "mysql") { 357 | $verSql = mysqli_get_server_info($this->conn); 358 | $version = explode("-", $verSql); 359 | $this->version = $version[0]; 360 | return $this->version; 361 | } else if ($this->adapter == "sqlite") { 362 | $this->version = sqlite_libversion(); 363 | return $this->version; 364 | } 365 | } 366 | 367 | } 368 | 369 | // returns the number of rows in a table 370 | function tableRowCount($table) { 371 | if ($this->conn) { 372 | if ($this->adapter == "mysql") { 373 | $countSql = $this->query("SELECT COUNT(*) AS `RowCount` FROM `" . $table . "`"); 374 | $count = (int)($this->result($countSql, 0, "RowCount")); 375 | return $count; 376 | } else if ($this->adapter == "sqlite") { 377 | $countSql = $this->query("SELECT COUNT(*) AS 'RowCount' FROM '" . $table . "'"); 378 | $count = (int)($this->result($countSql, 0, "RowCount")); 379 | return $count; 380 | } 381 | } 382 | } 383 | 384 | // gets column info for a table 385 | function describeTable($table) { 386 | if ($this->conn) { 387 | if ($this->adapter == "mysql") { 388 | return $this->query("DESCRIBE `" . $table . "`"); 389 | } else if ($this->adapter == "sqlite") { 390 | $columnSql = $this->query("SELECT sql FROM sqlite_master where tbl_name = '" . $table . "'"); 391 | $columnInfo = $this->result($columnSql, 0, "sql"); 392 | $columnStart = strpos($columnInfo, '('); 393 | $columns = substr($columnInfo, $columnStart+1, -1); 394 | $columns = split(',[^0-9]', $columns); 395 | 396 | $columnList = array(); 397 | 398 | foreach ($columns as $column) { 399 | $column = trim($column); 400 | $columnSplit = explode(" ", $column, 2); 401 | $columnName = $columnSplit[0]; 402 | $columnType = (sizeof($columnSplit) > 1) ? $columnSplit[1] : ""; 403 | $columnList[] = array($columnName, $columnType); 404 | } 405 | 406 | return $columnList; 407 | } 408 | } 409 | } 410 | 411 | /* 412 | Return names, row counts etc for every database, table and view in a JSON string 413 | */ 414 | function getMetadata() { 415 | $output = ''; 416 | if ($this->conn) { 417 | if ($this->adapter == "mysql" && version_compare($this->getVersion(), "5.0.0", ">=")) { 418 | $this->selectDB("information_schema"); 419 | $schemaSql = $this->query("SELECT `SCHEMA_NAME` FROM `SCHEMATA` ORDER BY `SCHEMA_NAME`"); 420 | if ($this->rowCount($schemaSql)) { 421 | while ($schema = $this->fetchAssoc($schemaSql)) { 422 | $output .= '{"name": "' . $schema['SCHEMA_NAME'] . '"'; 423 | // other interesting columns: TABLE_TYPE, ENGINE, TABLE_COLUMN and many more 424 | $tableSql = $this->query("SELECT `TABLE_NAME`, `TABLE_ROWS` FROM `TABLES` WHERE `TABLE_SCHEMA`='" . $schema['SCHEMA_NAME'] . "' ORDER BY `TABLE_NAME`"); 425 | if ($this->rowCount($tableSql)) { 426 | $output .= ',"items": ['; 427 | while ($table = $this->fetchAssoc($tableSql)) { 428 | 429 | if ($schema['SCHEMA_NAME'] == "information_schema") { 430 | $countSql = $this->query("SELECT COUNT(*) AS `RowCount` FROM `" . $table['TABLE_NAME'] . "`"); 431 | $rowCount = (int)($this->result($countSql, 0, "RowCount")); 432 | } else { 433 | $rowCount = (int)($table['TABLE_ROWS']); 434 | } 435 | 436 | $output .= '{"name":"' . $table['TABLE_NAME'] . '","rowcount":' . $rowCount . '},'; 437 | } 438 | 439 | if (substr($output, -1) == ",") 440 | $output = substr($output, 0, -1); 441 | 442 | $output .= ']'; 443 | } 444 | $output .= '},'; 445 | } 446 | $output = substr($output, 0, -1); 447 | } 448 | } else if ($this->adapter == "mysql") { 449 | $schemaSql = $this->listDatabases(); 450 | 451 | if ($this->rowCount($schemaSql)) { 452 | while ($schema = $this->fetchArray($schemaSql)) { 453 | $output .= '{"name": "' . $schema[0] . '"'; 454 | 455 | $this->selectDB($schema[0]); 456 | $tableSql = $this->listTables(); 457 | 458 | if ($this->rowCount($tableSql)) { 459 | $output .= ',"items": ['; 460 | while ($table = $this->fetchArray($tableSql)) { 461 | $countSql = $this->query("SELECT COUNT(*) AS `RowCount` FROM `" . $table[0] . "`"); 462 | $rowCount = (int)($this->result($countSql, 0, "RowCount")); 463 | $output .= '{"name":"' . $table[0] . '","rowcount":' . $rowCount . '},'; 464 | } 465 | 466 | if (substr($output, -1) == ",") 467 | $output = substr($output, 0, -1); 468 | 469 | $output .= ']'; 470 | } 471 | $output .= '},'; 472 | } 473 | $output = substr($output, 0, -1); 474 | } 475 | } else if ($this->adapter == "sqlite") { 476 | $output .= '{"name": "' . $this->db . '"'; 477 | 478 | $tableSql = $this->listTables(); 479 | 480 | if ($tableSql) { 481 | $output .= ',"items": ['; 482 | while ($tableRow = $this->fetchArray($tableSql)) { 483 | $countSql = $this->query("SELECT COUNT(*) AS 'RowCount' FROM '" . $tableRow[0] . "'"); 484 | $rowCount = (int)($this->result($countSql, 0, "RowCount")); 485 | $output .= '{"name":"' . $tableRow[0] . '","rowcount":' . $rowCount . '},'; 486 | } 487 | 488 | if (substr($output, -1) == ",") 489 | $output = substr($output, 0, -1); 490 | 491 | $output .= ']'; 492 | } 493 | $output .= '}'; 494 | } 495 | } 496 | return $output; 497 | } 498 | 499 | function error() { 500 | return $this->errorMessage; 501 | } 502 | 503 | } 504 | -------------------------------------------------------------------------------- /src/includes/types.php: -------------------------------------------------------------------------------- 1 | 13 | 14 | */ 15 | 16 | $typeList[] = "varchar"; 17 | $typeList[] = "char"; 18 | $typeList[] = "text"; 19 | $typeList[] = "tinytext"; 20 | $typeList[] = "mediumtext"; 21 | $typeList[] = "longtext"; 22 | $typeList[] = "tinyint"; 23 | $typeList[] = "smallint"; 24 | $typeList[] = "mediumint"; 25 | $typeList[] = "int"; 26 | $typeList[] = "bigint"; 27 | $typeList[] = "real"; 28 | $typeList[] = "double"; 29 | $typeList[] = "float"; 30 | $typeList[] = "decimal"; 31 | $typeList[] = "numeric"; 32 | $typeList[] = "date"; 33 | $typeList[] = "time"; 34 | $typeList[] = "datetime"; 35 | $typeList[] = "timestamp"; 36 | $typeList[] = "tinyblob"; 37 | $typeList[] = "blob"; 38 | $typeList[] = "mediumblob"; 39 | $typeList[] = "longblob"; 40 | $typeList[] = "binary"; 41 | $typeList[] = "varbinary"; 42 | $typeList[] = "bit"; 43 | $typeList[] = "enum"; 44 | $typeList[] = "set"; 45 | 46 | $textDTs[] = "text"; 47 | $textDTs[] = "mediumtext"; 48 | $textDTs[] = "longtext"; 49 | 50 | $numericDTs[] = "tinyint"; 51 | $numericDTs[] = "smallint"; 52 | $numericDTs[] = "mediumint"; 53 | $numericDTs[] = "int"; 54 | $numericDTs[] = "bigint"; 55 | $numericDTs[] = "real"; 56 | $numericDTs[] = "double"; 57 | $numericDTs[] = "float"; 58 | $numericDTs[] = "decimal"; 59 | $numericDTs[] = "numeric"; 60 | 61 | $binaryDTs[] = "tinyblob"; 62 | $binaryDTs[] = "blob"; 63 | $binaryDTs[] = "mediumblob"; 64 | $binaryDTs[] = "longblob"; 65 | $binaryDTs[] = "binary"; 66 | $binaryDTs[] = "varbinary"; 67 | 68 | $sqliteTypeList[] = "varchar"; 69 | $sqliteTypeList[] = "integer"; 70 | $sqliteTypeList[] = "float"; 71 | $sqliteTypeList[] = "varchar"; 72 | $sqliteTypeList[] = "nvarchar"; 73 | $sqliteTypeList[] = "text"; 74 | $sqliteTypeList[] = "boolean"; 75 | $sqliteTypeList[] = "clob"; 76 | $sqliteTypeList[] = "blob"; 77 | $sqliteTypeList[] = "timestamp"; 78 | $sqliteTypeList[] = "numeric"; 79 | 80 | ?> -------------------------------------------------------------------------------- /src/index.php: -------------------------------------------------------------------------------- 1 | 13 | 14 | */ 15 | 16 | include "functions.php"; 17 | 18 | loginCheck(false); 19 | 20 | outputPage(); 21 | 22 | ?> -------------------------------------------------------------------------------- /src/insert.php: -------------------------------------------------------------------------------- 1 | 13 | 14 | */ 15 | 16 | include "functions.php"; 17 | 18 | loginCheck(); 19 | 20 | requireDatabaseAndTableBeDefined(); 21 | 22 | if (isset($db)) 23 | $conn->selectDB($db); 24 | 25 | if (isset($table)) 26 | $structureSql = $conn->describeTable($table); 27 | 28 | if ($conn->isResultSet($structureSql) && $conn->getAdapter() == "mysql") { 29 | while ($structureRow = $conn->fetchAssoc($structureSql)) { 30 | $types[$structureRow['Field']] = $structureRow['Type']; 31 | } 32 | $structureSql = $conn->describeTable($table); 33 | } 34 | 35 | if ($conn->isResultSet($structureSql) || sizeof($structureSql) > 0) { 36 | 37 | if ($_POST) { 38 | 39 | $insertFields = ""; 40 | $insertValues = ""; 41 | 42 | foreach ($_POST as $key=>$value) { 43 | 44 | if ($conn->getAdapter() == "sqlite") { 45 | $insertFields .= $key . ","; 46 | } else { 47 | $insertFields .= "`" . $key . "`,"; 48 | } 49 | 50 | if (is_array($value)) { 51 | $value = implode(",", $value); 52 | } 53 | 54 | if (isset($types) && substr($value, 0, 2) == "0x" && isset($binaryDTs) && in_array($types[$key], $binaryDTs)) { 55 | $insertValues .= $conn->escapeString(urldecode($value)) . ","; 56 | } else { 57 | $insertValues .= "'" . $conn->escapeString(urldecode($value)) . "',"; 58 | } 59 | 60 | } 61 | 62 | $insertFields = substr($insertFields, 0, -1); 63 | $insertValues = substr($insertValues, 0, -1); 64 | 65 | if ($conn->getAdapter() == "sqlite") { 66 | $insertQuery = "INSERT INTO $table (" . $insertFields . ") VALUES (" . $insertValues . ")"; 67 | } else { 68 | $insertQuery = "INSERT INTO `$table` (" . $insertFields . ") VALUES (" . $insertValues . ")"; 69 | } 70 | 71 | $conn->query($insertQuery) or ($dbError = $conn->error()); 72 | 73 | $insertId = $conn->insertId(); 74 | 75 | if (isset($dbError)) { 76 | echo '
' . $dbError . '
'; 77 | } else { 78 | echo '
'; 79 | echo __("Your data has been inserted into the database."); 80 | if ($insertId) 81 | echo ' (Id: ' . $insertId . ')'; 82 | echo '
'; 83 | 84 | ?> 85 | 86 | 92 | 93 | 99 | 100 |
101 | 102 | getAdapter() == "sqlite") { 107 | 108 | if (sizeof($structureSql) > 0) { 109 | foreach ($structureSql as $column) { 110 | 111 | echo ''; 112 | echo ''; 117 | echo ""; 118 | echo ""; 119 | echo ' 143 | 144 | 145 | getAdapter() == "mysql") { 150 | 151 | if ($conn->isResultSet($structureSql)) { 152 | while ($structureRow = $conn->fetchAssoc($structureSql)) { 153 | 154 | preg_match("/^([a-z]+)(.([0-9]+).)?(.*)?$/", $structureRow['Type'], $matches); 155 | 156 | $curtype = $matches[1]; 157 | $cursizeQuotes = $matches[2]; 158 | $cursize = $matches[3]; 159 | $curextra = $matches[4]; 160 | 161 | echo ''; 162 | echo ''; 167 | echo ""; 168 | echo ""; 169 | echo ' 209 | 210 | 211 | 218 | 219 | 222 | 223 |
'; 113 | if (strpos($column[1], "primary key") > 0) echo ''; 114 | echo $column[0]; 115 | if (strpos($column[1], "primary key") > 0) echo ''; 116 | echo " " . $column[1] . '
'; 120 | 121 | if (strpos($column[1], "text") !== false) { 122 | echo ''; 127 | } else { 128 | echo ''; 138 | } 139 | 140 | ?> 141 | 142 |
'; 163 | if ($structureRow['Key'] == 'PRI') echo ''; 164 | echo $structureRow['Field']; 165 | if ($structureRow['Key'] == 'PRI') echo ''; 166 | echo " " . $curtype . $cursizeQuotes . ' ' . $structureRow['Extra'] . '
'; 170 | if ($structureRow['Type'] == "text") { 171 | echo ''; 175 | } 176 | elseif (substr($structureRow['Type'], 0, 4) == "enum") { 177 | $trimmed = substr($structureRow['Type'], 6, -2); 178 | $listOptions = explode("','", $trimmed); 179 | echo ''; 185 | } 186 | elseif (substr($structureRow['Type'], 0, 3) == "set") { 187 | $trimmed = substr($structureRow['Type'], 5, -2); 188 | $listOptions = explode("','", $trimmed); 189 | foreach ($listOptions as $option) { 190 | $id = $option . rand(1, 1000); 191 | echo '
'; 192 | } 193 | } else { 194 | echo ''; 204 | } 205 | 206 | ?> 207 | 208 |
220 | " /> 221 |
224 |
225 | 226 | 230 | 235 | 240 | 241 |
242 |

243 |

244 |
245 | 246 | -------------------------------------------------------------------------------- /src/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 | 14 | */ 15 | 16 | include "functions.php"; 17 | 18 | $adapter = (isset($sbconfig['DefaultAdapter'])) ? $sbconfig['DefaultAdapter'] : "mysql"; 19 | $host = (isset($sbconfig['DefaultHost'])) ? $sbconfig['DefaultHost'] : "localhost"; 20 | $user = (isset($sbconfig['DefaultUser'])) ? $sbconfig['DefaultUser'] : "root"; 21 | $pass = (isset($sbconfig['DefaultPass'])) ? $sbconfig['DefaultPass'] : ""; 22 | 23 | // SQLite only 24 | $database = (isset($sbconfig['DefaultDatabase'])) ? $sbconfig['DefaultDatabase'] : ""; 25 | 26 | if ($_POST) { 27 | if (isset($_POST['ADAPTER'])) 28 | $adapter = $_POST['ADAPTER']; 29 | 30 | if (isset($_POST['HOST'])) 31 | $host = $_POST['HOST']; 32 | 33 | if (isset($_POST['USER'])) 34 | $user = $_POST['USER']; 35 | 36 | if (isset($_POST['PASS'])) 37 | $pass = $_POST['PASS']; 38 | 39 | if (isset($_POST['DATABASE'])) 40 | $database = $_POST['DATABASE']; 41 | } 42 | 43 | if (!in_array($adapter, $adapterList)) { 44 | $adapter = "mysql"; 45 | } 46 | 47 | if (($adapter != "sqlite" && $host && $user && ($pass || $_POST)) || ($adapter == "sqlite" && $database)) { 48 | 49 | if ($adapter == "sqlite") { 50 | $connString = "sqlite:database=$database"; 51 | $connCheck = new SQL($connString); 52 | $user = ""; 53 | $pass = ""; 54 | } else { 55 | $connString = "$adapter:host=$host"; 56 | $connCheck = new SQL($connString, $user, $pass); 57 | } 58 | 59 | if ($connCheck->isConnected()) { 60 | $_SESSION['SB_LOGIN'] = true; 61 | $_SESSION['SB_LOGIN_STRING'] = $connString; 62 | $_SESSION['SB_LOGIN_USER'] = $user; 63 | $_SESSION['SB_LOGIN_PASS'] = $pass; 64 | 65 | $path = $_SERVER["SCRIPT_NAME"]; 66 | $pathSplit = explode("/", $path); 67 | 68 | $redirect = ""; 69 | 70 | for ($i=0; $i 94 | 95 | 96 | 97 | SQL Buddy 98 | 99 | " /> 100 | " /> 101 | " media="print" /> 102 | " /> 103 | 106 | 107 | 108 | 109 | 110 | 111 |
112 |
113 |
114 |
115 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 |

139 | 144 | 145 | 146 | 147 | 148 | '; 151 | } 152 | if (isset($_GET['timeout'])) { 153 | echo ''; 154 | } 155 | 156 | if (sizeof($adapterList) > 1) { 157 | 158 | ?> 159 | 160 | 161 | 180 | 181 | 186 |

' . $error . '
' . __("Your session has timed out. Please login again.") . '
162 | 179 |
187 | > 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 | 218 |
219 |
220 |
221 |
222 | 266 | 267 | -------------------------------------------------------------------------------- /src/logout.php: -------------------------------------------------------------------------------- 1 | 13 | 14 | */ 15 | 16 | if (!session_id()) 17 | session_start(); 18 | 19 | if (isset($_SESSION['SB_LOGIN'])) { 20 | $_SESSION['SB_LOGIN'] = null; 21 | unset($GLOBALS['_SESSION']['SB_LOGIN']); 22 | } 23 | 24 | if (isset($_SESSION['SB_LOGIN_STRING'])) { 25 | $_SESSION['SB_LOGIN_STRING'] = null; 26 | unset($GLOBALS['_SESSION']['SB_LOGIN_STRING']); 27 | } 28 | 29 | if (isset($_SESSION['SB_LOGIN_USER'])) { 30 | $_SESSION['SB_LOGIN_USER'] = null; 31 | unset($GLOBALS['_SESSION']['SB_LOGIN_USER']); 32 | } 33 | 34 | if (isset($_SESSION['SB_LOGIN_PASS'])) { 35 | $_SESSION['SB_LOGIN_PASS'] = null; 36 | unset($GLOBALS['_SESSION']['SB_LOGIN_PASS']); 37 | } 38 | 39 | header("Location: login.php"); 40 | 41 | ?> -------------------------------------------------------------------------------- /src/query.php: -------------------------------------------------------------------------------- 1 | 13 | 14 | */ 15 | 16 | include "functions.php"; 17 | 18 | loginCheck(); 19 | 20 | if (isset($db)) 21 | $conn->selectDB($db); 22 | 23 | if (isset($_POST['query'])) 24 | $query = $_POST['query']; 25 | 26 | echo '
'; 27 | 28 | if (isset($db)) { 29 | echo '' . sprintf(__("Run a query on the %s database"), $db) . '.'; 30 | } 31 | 32 | if (isset($query)) { 33 | $displayQuery = $query; 34 | } else if (isset($db) && isset($table) && $conn->getAdapter() == "mysql") { 35 | $displayQuery = "SELECT * FROM `$table` LIMIT 100"; 36 | } else if (isset($db) && isset($table) && $conn->getAdapter() == "sqlite") { 37 | $displayQuery = "SELECT * FROM '$table' LIMIT 100"; 38 | } 39 | 40 | ?> 41 | 42 |
43 | 44 | 45 | 53 | 56 | 57 |
46 | 52 | 54 | " /> 55 |
58 |
59 | 60 |
61 | 62 | '; 67 | 68 | require "includes/browse.php"; 69 | 70 | echo ''; 71 | } 72 | 73 | ?> 74 | -------------------------------------------------------------------------------- /src/serve.php: -------------------------------------------------------------------------------- 1 | 13 | 14 | */ 15 | 16 | include "config.php"; 17 | 18 | function compressCSS($input) { 19 | // remove comments 20 | $input = preg_replace("/\/\*.*\*\//Us", "", $input); 21 | 22 | // remove unnecessary characters 23 | $input = str_replace(":0px", ":0", $input); 24 | $input = str_replace(":0em", ":0", $input); 25 | $input = str_replace(" 0px", " 0", $input); 26 | $input = str_replace(" 0em", " 0", $input); 27 | $input = str_replace(";}", "}", $input); 28 | 29 | // remove spaces, etc 30 | $input = preg_replace('/\s\s+/', ' ', $input); 31 | $input = str_replace(" {", "{", $input); 32 | $input = str_replace("{ ", "{", $input); 33 | $input = str_replace("\n{", "{", $input); 34 | $input = str_replace("{\n", "{", $input); 35 | $input = str_replace(" }", "}", $input); 36 | $input = str_replace("} ", "}", $input); 37 | $input = str_replace(": ", ":", $input); 38 | $input = str_replace(" :", ":", $input); 39 | $input = str_replace(";\n", ";", $input); 40 | $input = str_replace(" ;", ";", $input); 41 | $input = str_replace("; ", ";", $input); 42 | $input = str_replace(", ", ",", $input); 43 | 44 | return trim($input); 45 | } 46 | 47 | function compressJS($input) { 48 | 49 | // remove comments 50 | $input = preg_replace("/\/\/.*\n/Us", "", $input); 51 | $input = preg_replace("/\/\*.*\*\//Us", "", $input); 52 | 53 | // remove spaces, etc 54 | $input = preg_replace("/\t/", "", $input); 55 | $input = preg_replace("/\n\n+/m", "\n", $input); 56 | $input = str_replace(";\n", ";", $input); 57 | $input = str_replace(" = ", "=", $input); 58 | $input = str_replace(" == ", "==", $input); 59 | $input = str_replace(" || ", "||", $input); 60 | $input = str_replace(" && ", "&&", $input); 61 | $input = str_replace(")\n{", "){", $input); 62 | $input = str_replace("if (", "if(", $input); 63 | 64 | return trim($input); 65 | } 66 | 67 | if (isset($_GET['file'])) { 68 | 69 | $filename = $_GET['file']; 70 | 71 | if (!(strpos($filename, "css/") === 0 || strpos($filename, "themes/") === 0 || strpos($filename, "js/") === 0)) 72 | exit; 73 | 74 | if (strpos($filename, "..") !== false) 75 | exit; 76 | 77 | if (file_exists($filename)) { 78 | if (extension_loaded('zlib') && ((isset($sbconfig['EnableGzip']) && $sbconfig['EnableGzip'] == true) || !isset($sbconfig['EnableGzip']))) { 79 | ob_start("ob_gzhandler"); 80 | } else { 81 | ob_start(); 82 | } 83 | 84 | $last_modified_time = filemtime($filename); 85 | $etag = md5_file($filename); 86 | 87 | header("Last-Modified: " . gmdate("D, d M Y H:i:s", $last_modified_time) . " GMT"); 88 | header("Expires: " . gmdate("D, d M Y H:i:s", time()+24*60*60*60) . " GMT"); 89 | header("Etag: $etag"); 90 | 91 | 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)) { 92 | header("HTTP/1.1 304 Not Modified"); 93 | exit; 94 | } 95 | 96 | $contents = file_get_contents($filename); 97 | 98 | if (substr($filename, -4) == ".css") { 99 | header("Content-Type: text/css; charset=utf-8"); 100 | $contents = compressCSS($contents); 101 | } else if (substr($filename, -3) == ".js" && strpos($filename, "mootools") === false) { 102 | header("Content-Type: application/x-javascript; charset=utf-8"); 103 | $contents = compressJS($contents); 104 | } else if (substr($filename, -3) == ".js") { 105 | header("Content-Type: application/x-javascript; charset=utf-8"); 106 | } 107 | 108 | echo $contents; 109 | 110 | ob_end_flush(); 111 | } else { 112 | echo "File doesn't exist!"; 113 | } 114 | } 115 | 116 | ?> -------------------------------------------------------------------------------- /src/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 | } -------------------------------------------------------------------------------- /src/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 | } -------------------------------------------------------------------------------- /src/themes/bittersweet/images/header.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deliciousbrains/sqlbuddy/8d684096dd5382bf4d85246430dde8afbfc539f3/src/themes/bittersweet/images/header.png -------------------------------------------------------------------------------- /src/themes/bittersweet/images/initLoad-dark.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deliciousbrains/sqlbuddy/8d684096dd5382bf4d85246430dde8afbfc539f3/src/themes/bittersweet/images/initLoad-dark.png -------------------------------------------------------------------------------- /src/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 | } -------------------------------------------------------------------------------- /src/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 | } -------------------------------------------------------------------------------- /src/themes/classic/images/corner-bl.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deliciousbrains/sqlbuddy/8d684096dd5382bf4d85246430dde8afbfc539f3/src/themes/classic/images/corner-bl.png -------------------------------------------------------------------------------- /src/themes/classic/images/corner-br.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deliciousbrains/sqlbuddy/8d684096dd5382bf4d85246430dde8afbfc539f3/src/themes/classic/images/corner-br.png -------------------------------------------------------------------------------- /src/themes/classic/images/corner-tl.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deliciousbrains/sqlbuddy/8d684096dd5382bf4d85246430dde8afbfc539f3/src/themes/classic/images/corner-tl.png -------------------------------------------------------------------------------- /src/themes/classic/images/corner-tr.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deliciousbrains/sqlbuddy/8d684096dd5382bf4d85246430dde8afbfc539f3/src/themes/classic/images/corner-tr.png -------------------------------------------------------------------------------- /src/themes/classic/images/header.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deliciousbrains/sqlbuddy/8d684096dd5382bf4d85246430dde8afbfc539f3/src/themes/classic/images/header.png -------------------------------------------------------------------------------- /src/themes/classic/images/shading.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deliciousbrains/sqlbuddy/8d684096dd5382bf4d85246430dde8afbfc539f3/src/themes/classic/images/shading.png -------------------------------------------------------------------------------- /src/users.php: -------------------------------------------------------------------------------- 1 | 13 | 14 | */ 15 | 16 | include "functions.php"; 17 | 18 | loginCheck(); 19 | 20 | function removeAdminPrivs($priv) { 21 | if ($priv == "FILE" || $priv == "PROCESS" || $priv == "RELOAD" || $priv == "SHUTDOWN" || $priv == "SUPER") 22 | return false; 23 | else 24 | return true; 25 | } 26 | 27 | if ($_POST) { 28 | 29 | if (isset($_POST['NEWHOST'])) 30 | $newHost = $_POST['NEWHOST']; 31 | else 32 | $newHost = "localhost"; 33 | 34 | if (isset($_POST['NEWNAME'])) 35 | $newName = $_POST['NEWNAME']; 36 | 37 | if (isset($_POST['NEWPASS'])) 38 | $newPass = $_POST['NEWPASS']; 39 | 40 | if (isset($_POST['ACCESSLEVEL'])) 41 | $accessLevel = $_POST['ACCESSLEVEL']; 42 | else 43 | $accessLevel = "GLOBAL"; 44 | 45 | if ($accessLevel != "LIMITED") 46 | $accessLevel = "GLOBAL"; 47 | 48 | if (isset($_POST['DBLIST'])) 49 | $dbList = $_POST['DBLIST']; 50 | else 51 | $dbList = array(); 52 | 53 | if (isset($_POST['NEWCHOICE'])) 54 | $newChoice = $_POST['NEWCHOICE']; 55 | 56 | if (isset($_POST['NEWPRIVILEGES'])) 57 | $newPrivileges = $_POST['NEWPRIVILEGES']; 58 | 59 | if (isset($newName) && ($accessLevel == "GLOBAL" || ($accessLevel == "LIMITED" && sizeof($dbList) > 0))) { 60 | 61 | if ($newChoice == "ALL") { 62 | $privList = "ALL"; 63 | } else { 64 | 65 | if (sizeof($newPrivileges) > 0) { 66 | if ($accessLevel == "LIMITED") { 67 | $newPrivileges = array_filter($newPrivileges, "removeAdminPrivs"); 68 | } 69 | 70 | $privList = implode(", ", $newPrivileges); 71 | 72 | } else { 73 | $privList = "USAGE"; 74 | } 75 | } 76 | 77 | if ($accessLevel == "LIMITED") { 78 | foreach ($dbList as $theDb) { 79 | $newQuery = "GRANT " . $privList; 80 | 81 | $newQuery .= " ON `$theDb`.*"; 82 | 83 | $newQuery .= " TO '" . $newName . "'@'" . $newHost . "'"; 84 | 85 | if ($newPass) 86 | $newQuery .= " IDENTIFIED BY '" . $newPass . "'"; 87 | 88 | if (isset($_POST['GRANTOPTION'])) 89 | $newQuery .= " WITH GRANT OPTION"; 90 | 91 | $conn->query($newQuery) or ($dbError = $conn->error()); 92 | } 93 | } else { 94 | $newQuery = "GRANT " . $privList; 95 | 96 | $newQuery .= " ON *.*"; 97 | 98 | $newQuery .= " TO '" . $newName . "'@'" . $newHost . "'"; 99 | 100 | if ($newPass) 101 | $newQuery .= " IDENTIFIED BY '" . $newPass . "'"; 102 | 103 | if (isset($_POST['GRANTOPTION'])) 104 | $newQuery .= " WITH GRANT OPTION"; 105 | 106 | $conn->query($newQuery) or ($dbError = $conn->error()); 107 | } 108 | 109 | $conn->query("FLUSH PRIVILEGES") or ($dbError = $conn->error()); 110 | 111 | } 112 | } 113 | 114 | $connected = $conn->selectDB("mysql"); 115 | 116 | // delete users 117 | if (isset($_POST['deleteUsers']) && $connected) { 118 | $deleteUsers = $_POST['deleteUsers']; 119 | 120 | // boom! 121 | $userList = explode(";", $deleteUsers); 122 | 123 | foreach ($userList as $each) { 124 | $split = explode("@", $each, 2); 125 | 126 | if (isset($split[0])) 127 | $user = trim($split[0]); 128 | 129 | if (isset($split[1])) 130 | $host = trim($split[1]); 131 | 132 | if (isset($user) && isset($host)) { 133 | $conn->query("REVOKE ALL PRIVILEGES ON *.* FROM '$user'@'$host'"); 134 | $conn->query("REVOKE GRANT OPTION ON *.* FROM '$user'@'$host'"); 135 | $conn->query("DELETE FROM `user` WHERE `User`='$user' AND `Host`='$host'"); 136 | $conn->query("DELETE FROM `db` WHERE `User`='$user' AND `Host`='$host'"); 137 | $conn->query("DELETE FROM `tables_priv` WHERE `User`='$user' AND `Host`='$host'"); 138 | $conn->query("DELETE FROM `columns_priv` WHERE `User`='$user' AND `Host`='$host'"); 139 | } 140 | } 141 | $conn->query("FLUSH PRIVILEGES"); 142 | } 143 | 144 | if (isset($dbError)) { 145 | echo '
'; 146 | echo '' . __("Error performing operation") . '

' . $dbError . '

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

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

422 |

423 | 428 |
429 |

430 |

431 |
432 | 436 | 437 | 438 | --------------------------------------------------------------------------------