. // /////////////////////////////////////////////////////////////////////////// //adicionado por edmar include_once ("../../ms_configura.php"); $editor = false; if (strtolower($_SERVER['HTTP_HOST']) == "localhost") {$editor = true;} if($editores != ""){ foreach ($editores as $e){ $ip = "UNKNOWN"; if (getenv("HTTP_CLIENT_IP")) $ip = getenv("HTTP_CLIENT_IP"); else if(getenv("HTTP_X_FORWARDED_FOR")) $ip = getenv("HTTP_X_FORWARDED_FOR"); else if(getenv("REMOTE_ADDR")) $ip = getenv("REMOTE_ADDR"); else $ip = "UNKNOWN"; if ($e == $ip){$editor=true;} } } if($editor == false) {echo "Vc não é um editor cadastrado em i3geo/ms_configura.php";exit;} //please report any bugs you encounter to http://code.google.com/p/phpliteadmin/issues/list //password to gain access (change this to something more secure than 'admin') //$password = "admin"; include_once("senha.php"); if($conexaoadmin == ""){ //directory relative to this file to search for SQLite databases (if false, manually list databases below) $directory = "../../admin"; //an array of databases that will appear in the application (if $directory is anything but false, $databases will be ignored) //if any of the databases do not exist as they are referenced by their path, they will be created automatically if possible //the SQLite version of each database is determined automatically $databases = array ( array ( "path"=> "admin.db", "name"=> "admin.db" ) ); } else{ include_once($conexaoadmin); //$arquivosqlite = $locaplic."/sfb/admin.db"; $directory = dirname($arquivosqlite); $databases = array ( array ( "path"=> basename($arquivosqlite), "name"=> "admin.db" ) ); $conAdmin = ""; $conAdminw = ""; $dbhw = ""; $dbh = ""; } // What should the name of the cookie be which contains the current password? // Changing this allows multiple phpLiteAdmin installs to work under the same domain. $cookie_name = 'pla3412'; //end of the variables you may need to edit session_start(); //don't mess with this - required for the login session date_default_timezone_set(date_default_timezone_get()); //needed to fix STRICT warnings about timezone issues //toggle error reporting //ini_set("display_errors", 1); //error_reporting(E_STRICT | E_ALL); $startTimeTot = microtime(true); //start the timer to record page load time //the salt and password encrypting is probably unnecessary protection but is done just for the sake of being very secure //create a random salt for this session if a cookie doesn't already exist for it if(!isset($_SESSION[$cookie_name.'_salt']) && !isset($_COOKIE[$cookie_name.'_salt'])) { $n = rand(10e16, 10e20); $_SESSION[$cookie_name.'_salt'] = base_convert($n, 10, 36); } else if(!isset($_SESSION[$cookie_name.'_salt']) && isset($_COOKIE[$cookie_name.'_salt'])) //session doesn't exist, but cookie does so grab it { $_SESSION[$cookie_name.'_salt'] = $_COOKIE[$cookie_name.'_salt']; } //build the basename of this file for later reference $info = pathinfo($_SERVER['PHP_SELF']); $thisName = $info['basename']; //constants define("PROJECT", "phpLiteAdmin"); define("VERSION", "1.8.6"); define("PAGE", $thisName); define("COOKIENAME", $cookie_name); define("SYSTEMPASSWORD", $password); // Makes things easier. define("SYSTEMPASSWORDENCRYPTED", md5($password."_".$_SESSION[$cookie_name.'_salt'])); //extra security - salted and encrypted password used for checking define("FORCETYPE", false); //force the extension that will be used (set to false in almost all circumstances except debugging) //data types array $types = array("INTEGER", "REAL", "TEXT", "BLOB"); define("DATATYPES", serialize($types)); //available SQLite functions array $functions = array("abs", "date", "datetime", "hex", "julianday", "length", "lower", "ltrim", "random", "round", "rtrim", "soundex", "time", "trim", "typeof", "upper"); define("FUNCTIONS", serialize($functions)); //if the user wants to scan a directory for databases, do so if($directory!==false) { if($directory[strlen($directory)-1]=="/") //if user has a trailing slash in the directory, remove it $directory = substr($directory, 0, strlen($directory)-1); if(is_dir($directory)) //make sure the directory is valid { $arr = scandir($directory); $databases = array(); $j = 0; for($i=0; $i"; echo "The directory you specified to scan for databases does not exist or is not a directory."; echo ""; exit(); } } // // Authorization class // Maintains user's logged-in state and security of application // class Authorization { public function grant($remember) { if($remember) //user wants to be remembered, so set a cookie { $expire = time()+60*60*24*30; //set expiration to 1 month from now setcookie(COOKIENAME, SYSTEMPASSWORD, $expire); setcookie(COOKIENAME."_salt", $_SESSION[COOKIENAME.'_salt'], $expire); } else { //user does not want to be remembered, so destroy any potential cookies setcookie(COOKIENAME, "", time()-86400); setcookie(COOKIENAME."_salt", "", time()-86400); unset($_COOKIE[COOKIENAME]); unset($_COOKIE[COOKIENAME.'_salt']); } $_SESSION[COOKIENAME.'password'] = SYSTEMPASSWORDENCRYPTED; } public function revoke() { //destroy everything - cookies and session vars setcookie(COOKIENAME, "", time()-86400); setcookie(COOKIENAME."_salt", "", time()-86400); unset($_COOKIE[COOKIENAME]); unset($_COOKIE[COOKIENAME.'_salt']); session_unset(); session_destroy(); } public function isAuthorized() { // Is this just session long? (What!?? -DI) if((isset($_SESSION[COOKIENAME.'password']) && $_SESSION[COOKIENAME.'password'] == SYSTEMPASSWORDENCRYPTED) || (isset($_COOKIE[COOKIENAME]) && isset($_COOKIE[COOKIENAME.'_salt']) && md5($_COOKIE[COOKIENAME]."_".$_COOKIE[COOKIENAME.'_salt']) == SYSTEMPASSWORDENCRYPTED)) return true; else { return false; } } } // // Database class // Generic database abstraction class to manage interaction with database without worrying about SQLite vs. PHP versions // class Database { protected $db; //reference to the DB object protected $type; //the extension for PHP that handles SQLite protected $data; protected $lastResult; public function __construct($data) { $this->data = $data; try { if(file_exists($this->data["path"]) && !is_writable($this->data["path"])) //make sure the actual database file is writable { echo "
"; echo "The database, '".$this->data["path"]."', is not writable. The application is unusable until you make it writable."; echo "
"; echo ""; echo "
"; echo "

"; exit(); } if(!file_exists($this->data["path"]) && !is_writable(dirname($this->data["path"]))) //make sure the containing directory is writable if the database does not exist { echo "
"; echo "The database, '".$this->data["path"]."', does not exist and cannot be created because the containing directory, '".dirname($this->data["path"])."', is not writable. The application is unusable until you make it writable."; echo "
"; echo ""; echo "
"; echo "

"; exit(); } $ver = $this->getVersion(); switch(true) { case (FORCETYPE=="PDO" || ((FORCETYPE==false || $ver!=-1) && class_exists("PDO") && ($ver==-1 || $ver==3))): $this->db = new PDO("sqlite:".$this->data['path']); if($this->db!=NULL) { $this->type = "PDO"; break; } case (FORCETYPE=="SQLite3" || ((FORCETYPE==false || $ver!=-1) && class_exists("SQLite3") && ($ver==-1 || $ver==3))): $this->db = new SQLite3($this->data['path']); if($this->db!=NULL) { $this->type = "SQLite3"; break; } case (FORCETYPE=="SQLiteDatabase" || ((FORCETYPE==false || $ver!=-1) && class_exists("SQLiteDatabase") && ($ver==-1 || $ver==2))): $this->db = new SQLiteDatabase($this->data['path']); if($this->db!=NULL) { $this->type = "SQLiteDatabase"; break; } default: $this->showError(); exit(); } } catch(Exception $e) { $this->showError(); exit(); } } public function showError() { $classPDO = class_exists("PDO"); $classSQLite3 = class_exists("SQLite3"); $classSQLiteDatabase = class_exists("SQLiteDatabase"); if($classPDO) $strPDO = "installed"; else $strPDO = "not installed"; if($classSQLite3) $strSQLite3 = "installed"; else $strSQLite3 = "not installed"; if($classSQLiteDatabase) $strSQLiteDatabase = "installed"; else $strSQLiteDatabase = "not installed"; echo "
"; echo "There was a problem setting up your database, ".$this->getPath().". An attempt will be made to find out what's going on so you can fix the problem more easily.

"; echo "Checking supported SQLite PHP extensions...

"; echo "PDO: ".$strPDO."
"; echo "SQLite3: ".$strSQLite3."
"; echo "SQLiteDatabase: ".$strSQLiteDatabase."

...done.


"; if(!$classPDO && !$classSQLite3 && !$classSQLiteDatabase) echo "It appears that none of the supported SQLite library extensions are available in your installation of PHP. You may not use ".PROJECT." until you install at least one of them."; else { if(!$classPDO && !$classSQLite3 && $this->getVersion()==3) echo "It appears that your database is of SQLite version 3 but your installation of PHP does not contain the necessary extensions to handle this version. To fix the problem, either delete the database and allow ".PROJECT." to create it automatically or recreate it manually as SQLite version 2."; else if(!$classSQLiteDatabase && $this->getVersion()==2) echo "It appears that your database is of SQLite version 2 but your installation of PHP does not contain the necessary extensions to handle this version. To fix the problem, either delete the database and allow ".PROJECT." to create it automatically or recreate it manually as SQLite version 3."; else echo "The problem cannot be diagnosed properly. Please email me at daneiracleous@gmail.com with your database as an attachment and the contents of this error message. It may be that your database is simply not a valid SQLite database, but this is not certain."; } echo "

"; } public function __destruct() { if($this->db) $this->close(); } //get the exact PHP extension being used for SQLite public function getType() { return $this->type; } //get the name of the database public function getName() { return $this->data["name"]; } //get the filename of the database public function getPath() { return $this->data["path"]; } //get the version of the database public function getVersion() { if(file_exists($this->data['path'])) //make sure file exists before getting its contents { $content = strtolower(file_get_contents($this->data['path'], NULL, NULL, 0, 40)); //get the first 40 characters of the database file $p = strpos($content, "** this file contains an sqlite 2"); //this text is at the beginning of every SQLite2 database if($p!==false) //the text is found - this is version 2 return 2; else return 3; } else //return -1 to indicate that it does not exist and needs to be created { return -1; } } //get the size of the database public function getSize() { return round(filesize($this->data["path"])*0.0009765625, 1)." Kb"; } //get the last modified time of database public function getDate() { return date("g:ia \o\\n F j, Y", filemtime($this->data["path"])); } //get number of affected rows from last query public function getAffectedRows() { if($this->type=="PDO") return $this->lastResult->rowCount(); else if($this->type=="SQLite3") return $this->db->changes(); else if($this->type=="SQLiteDatabase") return $this->db->changes(); } public function close() { if($this->type=="PDO") $this->db = NULL; else if($this->type=="SQLite3") $this->db->close(); else if($this->type=="SQLiteDatabase") $this->db = NULL; } public function beginTransaction() { $this->query("BEGIN"); } public function commitTransaction() { $this->query("COMMIT"); } public function rollbackTransaction() { $this->query("ROLLBACK"); } //generic query wrapper public function query($query, $ignoreAlterCase=false) { if(strtolower(substr(ltrim($query),0,5))=='alter' && $ignoreAlterCase==false) //this query is an ALTER query - call the necessary function { $queryparts = preg_split("/[\s]+/", $query, 4, PREG_SPLIT_NO_EMPTY); $tablename = $queryparts[2]; $alterdefs = $queryparts[3]; //echo $query; $result = $this->alterTable($tablename, $alterdefs); } else //this query is normal - proceed as normal $result = $this->db->query($query); if(!$result) return NULL; $this->lastResult = $result; return $result; } //wrapper for an INSERT and returns the ID of the inserted row public function insert($query) { $result = $this->query($query); if($this->type=="PDO") return $this->db->lastInsertId(); else if($this->type=="SQLite3") return $this->db->lastInsertRowID(); else if($this->type=="SQLiteDatabase") return $this->db->lastInsertRowid(); } //returns an array for SELECT public function select($query, $mode="both") { $result = $this->query($query); if(!$result) //make sure the result is valid return NULL; if($this->type=="PDO") { if($mode=="assoc") $mode = PDO::FETCH_ASSOC; else if($mode=="num") $mode = PDO::FETCH_NUM; else $mode = PDO::FETCH_BOTH; return $result->fetch($mode); } else if($this->type=="SQLite3") { if($mode=="assoc") $mode = SQLITE3_ASSOC; else if($mode=="num") $mode = SQLITE3_NUM; else $mode = SQLITE3_BOTH; return $result->fetchArray($mode); } else if($this->type=="SQLiteDatabase") { if($mode=="assoc") $mode = SQLITE_ASSOC; else if($mode=="num") $mode = SQLITE_NUM; else $mode = SQLITE_BOTH; return $result->fetch($mode); } } //returns an array of arrays after doing a SELECT public function selectArray($query, $mode="both") { $result = $this->query($query); if(!$result) //make sure the result is valid return NULL; if($this->type=="PDO") { if($mode=="assoc") $mode = PDO::FETCH_ASSOC; else if($mode=="num") $mode = PDO::FETCH_NUM; else $mode = PDO::FETCH_BOTH; return $result->fetchAll($mode); } else if($this->type=="SQLite3") { if($mode=="assoc") $mode = SQLITE3_ASSOC; else if($mode=="num") $mode = SQLITE3_NUM; else $mode = SQLITE3_BOTH; $arr = array(); $i = 0; while($res = $result->fetchArray($mode)) { $arr[$i] = $res; $i++; } return $arr; } else if($this->type=="SQLiteDatabase") { if($mode=="assoc") $mode = SQLITE_ASSOC; else if($mode=="num") $mode = SQLITE_NUM; else $mode = SQLITE_BOTH; return $result->fetchAll($mode); } } //function that is called for an alter table statement in a query //code borrowed with permission from http://code.jenseng.com/db/ public function alterTable($table, $alterdefs) { if($alterdefs != '') { $tempQuery = "SELECT sql,name,type FROM sqlite_master WHERE tbl_name = '".$table."' ORDER BY type DESC"; $result = $this->query($tempQuery); $resultArr = $this->selectArray($tempQuery); if(sizeof($resultArr)>0) { $row = $this->select($tempQuery); //table sql $tmpname = 't'.time(); $origsql = trim(preg_replace("/[\s]+/", " ", str_replace(",", ", ",preg_replace("/[\(]/", "( ", $row['sql'], 1)))); $createtemptableSQL = 'CREATE TEMPORARY '.substr(trim(preg_replace("'".$table."'", $tmpname, $origsql, 1)), 6); $createindexsql = array(); $i = 0; $defs = preg_split("/[,]+/",$alterdefs, -1, PREG_SPLIT_NO_EMPTY); $prevword = $table; $oldcols = preg_split("/[,]+/", substr(trim($createtemptableSQL), strpos(trim($createtemptableSQL), '(')+1), -1, PREG_SPLIT_NO_EMPTY); $newcols = array(); for($i=0; $iquery($createtesttableSQL); if(!$tempResult) return false; $droptempsql = 'DROP TABLE '.$tmpname; $tempResult = $this->query($droptempsql); //end block $createnewtableSQL = 'CREATE '.substr(trim(preg_replace("'".$tmpname."'", $table, $createtesttableSQL, 1)), 17); $newcolumns = ''; $oldcolumns = ''; reset($newcols); while(list($key,$val) = each($newcols)) { $newcolumns .= ($newcolumns?', ':'').$val; $oldcolumns .= ($oldcolumns?', ':'').$key; } $copytonewsql = 'INSERT INTO '.$table.'('.$newcolumns.') SELECT '.$oldcolumns.' FROM '.$tmpname; $this->query($createtemptableSQL); //create temp table $this->query($copytotempsql); //copy to table $this->query($dropoldsql); //drop old table $this->query($createnewtableSQL); //recreate original table $this->query($copytonewsql); //copy back to original table $this->query($droptempsql); //drop temp table } else { return false; } return true; } } //multiple query execution public function multiQuery($query) { if($this->type=="PDO") { $this->db->exec($query); } else if($this->type=="SQLite3") { $this->db->exec($query); } else { $this->db->queryExec($query); } } //get number of rows in table public function numRows($table) { $result = $this->select("SELECT Count(*) FROM ".$table); return $result[0]; } //correctly escape a string to be injected into an SQL query public function quote($value) { if($this->type=="PDO") { return $this->db->quote($value); } else if($this->type=="SQLite3") { return $this->db->escapeString($value); } else { return "'".$value."'"; } } //correctly format a string value from a table before showing it public function formatString($value) { return htmlspecialchars(stripslashes($value)); } //import public function import($query) { $this->multiQuery($query); } //export public function export($tables, $drop, $structure, $data, $transaction, $comments) { if($comments) { echo "----\r\n"; echo "-- phpLiteAdmin database dump (http://phpliteadmin.googlecode.com)\r\n"; echo "-- phpLiteAdmin version: ".VERSION."\r\n"; echo "-- Exported on ".date('M jS, Y, h:i:sA')."\r\n"; echo "-- Database file: ".$this->getPath()."\r\n"; echo "----\r\n"; } $query = "SELECT * FROM sqlite_master WHERE type='table' OR type='index' ORDER BY type DESC"; $result = $this->selectArray($query); //iterate through each table for($i=0; $iselectArray($query, "assoc"); if($comments) { echo "\r\n----\r\n"; echo "-- Data dump for ".$result[$i]['tbl_name'].", a total of ".sizeof($arr)." rows\r\n"; echo "----\r\n"; } $query = "PRAGMA table_info('".$result[$i]['tbl_name']."')"; $temp = $this->selectArray($query); $cols = array(); $vals = array(); for($z=0; $zquote($arr[$z][$cols[$y]]); } } if($transaction) echo "BEGIN TRANSACTION;\r\n"; for($j=0; $jrevoke(); else if(isset($_POST['login']) || isset($_POST['proc_login'])) //user has attempted to log in { $_POST['login'] = true; if($_POST['password']==SYSTEMPASSWORD) //make sure passwords match before granting authorization { if(isset($_POST['remember'])) $auth->grant(true); else $auth->grant(false); } } //user is downloading the exported database file if(isset($_POST['export'])) { header('Content-Type: text/sql'); header('Content-Disposition: attachment; filename="'.$_POST['filename'].'.'.$_POST['export_type'].'";'); if(isset($_POST['tables'])) $tables = $_POST['tables']; else { $tables = array(); $tables[0] = $_POST['single_table']; } $drop = isset($_POST['drop']); $structure = isset($_POST['structure']); $data = isset($_POST['data']); $transaction = isset($_POST['transaction']); $comments = isset($_POST['comments']); $db = new Database($databases[$_SESSION[COOKIENAME.'currentDB']]); echo $db->export($tables, $drop, $structure, $data, $transaction, $comments); exit(); } //user is importing a file if(isset($_POST['import'])) { $data = file_get_contents($_FILES["file"]["tmp_name"]); $db = new Database($databases[$_SESSION[COOKIENAME.'currentDB']]); $db->import($data); } // here begins the HTML. ?> <?php echo PROJECT ?> "; } ?> "; echo "It appears that the PHP directive, 'register_globals' is enabled. This is bad. You need to disable it before continuing."; echo ""; exit(); } if(!$auth->isAuthorized()) //user is not authorized - display the login screen { echo "
"; echo "

v".VERSION."

"; echo "
"; if(isset($_POST['login'])) echo "Incorrect password.

"; echo "
"; echo "Password:
"; echo " Remember me

"; echo "Não sabe a senha? Veja no arquivo i3geo/pacotes/phpliteadmin/senha.php

"; echo "Além de saber a senha, você precisa ser um administrador cadastrado em i3geo/ms_configura.php

"; echo ""; echo ""; echo "
"; echo "
"; echo "
"; echo "
"; echo "
"; $endTimeTot = microtime(true); $timeTot = round(($endTimeTot - $startTimeTot), 4); echo "Powered by ".PROJECT." | Page generated in ".$timeTot." seconds."; echo "
"; } else //user is authorized - display the main application { if(!isset($_SESSION[COOKIENAME.'currentDB'])) $_SESSION[COOKIENAME.'currentDB'] = 0; //set the current database to the first in the array (default) if(sizeof($databases)>0) $currentDB = $databases[0]; else //the database array is empty - show error and halt execution { echo "
"; echo "Error: you have not specified any databases to manage."; echo "

"; exit(); } if(isset($_POST['database_switch'])) //user is switching database with drop-down menu { $_SESSION[COOKIENAME."currentDB"] = $_POST['database_switch']; $currentDB = $databases[$_SESSION[COOKIENAME.'currentDB']]; } else if(isset($_GET['switchdb'])) { $_SESSION[COOKIENAME."currentDB"] = $_GET['switchdb']; $currentDB = $databases[$_SESSION[COOKIENAME.'currentDB']]; } if(isset($_SESSION[COOKIENAME.'currentDB'])) $currentDB = $databases[$_SESSION[COOKIENAME.'currentDB']]; //create the objects $db = new Database($currentDB); //create the Database object //switch board for various operations a user could have requested - these actions are invisible and produce no output if(isset($_GET['action']) && isset($_GET['confirm'])) { switch($_GET['action']) { //table actions /////////////////////////////////////////////// create table case "table_create": $num = intval($_POST['rows']); $name = $_POST['tablename']; $query = "CREATE TABLE ".$name."("; for($i=0; $i<$num; $i++) { if($_POST[$i.'_field']!="") { $query .= $_POST[$i.'_field']." "; $query .= $_POST[$i.'_type']." "; if(isset($_POST[$i.'_primarykey'])) $query .= "PRIMARY KEY "; if(isset($_POST[$i.'_notnull'])) $query .= "NOT NULL "; if($_POST[$i.'_defaultvalue']!="") { if($_POST[$i.'_type']=="INTEGER") $query .= "default ".$_POST[$i.'_defaultvalue']." "; else $query .= "default '".$_POST[$i.'_defaultvalue']."' "; } $query = substr($query, 0, sizeof($query)-2); $query .= ", "; } } $query = substr($query, 0, sizeof($query)-3); $query .= ")"; $result = $db->query($query); if(!$result) $error = true; $completed = "Table '".$_POST['tablename']."' has been created.
".$query.""; break; /////////////////////////////////////////////// empty table case "table_empty": $query = "DELETE FROM ".$_POST['tablename']; $result = $db->query($query); if(!$result) $error = true; $query = "VACUUM"; $result = $db->query($query); if(!$result) $error = true; $completed = "Table '".$_POST['tablename']."' has been emptied.
".$query.""; break; /////////////////////////////////////////////// drop table case "table_drop": $query = "DROP TABLE ".$_POST['tablename']; $db->query($query); $completed = "Table '".$_POST['tablename']."' has been dropped."; break; /////////////////////////////////////////////// rename table case "table_rename": $query = "ALTER TABLE ".$_POST['oldname']." RENAME TO ".$_POST['newname']; if($db->getVersion()==3) $result = $db->query($query, true); else $result = $db->query($query, false); if(!$result) $error = true; $completed = "Table '".$_POST['oldname']."' has been renamed to '".$_POST['newname']."'.
".$query.""; break; //row actions /////////////////////////////////////////////// create row case "row_create": $completed = ""; $num = $_POST['numRows']; $fields = explode(":", $_POST['fields']); $z = 0; for($i=0; $i<$num; $i++) { if(!isset($_POST[$i.":ignore"])) { $query = "INSERT INTO ".$_GET['table']." ("; for($j=0; $jquote($value); if($function!="") $query .= ")"; $query .= ","; } $query = substr($query, 0, sizeof($query)-2); $query .= ")"; $result = $db->query($query); if(!$result) $error = true; $completed .= "".$query."
"; $z++; } } $completed = $z." row(s) inserted.

".$completed; break; /////////////////////////////////////////////// delete row case "row_delete": $pks = explode(":", $_GET['pk']); $str = $pks[0]; $query = "DELETE FROM ".$_GET['table']." WHERE ROWID = ".$pks[0]; for($i=1; $iquery($query); if(!$result) $error = true; $completed = sizeof($pks)." row(s) deleted.
".$query.""; break; /////////////////////////////////////////////// edit row case "row_edit": $pks = explode(":", $_GET['pk']); $fields = explode(":", $_POST['fieldArray']); $completed = sizeof($pks)." row(s) affected.

"; for($i=0; $iquote($_POST[$pks[$i].":".$fields[$j]]); if($function!="") $query .= ")"; $query .= ", "; } $query = substr($query, 0, sizeof($query)-3); $query .= " WHERE ROWID = ".$pks[$i]; $result = $db->query($query); if(!$result) { $error = true; } $completed .= "".$query."
"; } break; //column actions /////////////////////////////////////////////// create column case "column_create": $num = intval($_POST['rows']); for($i=0; $i<$num; $i++) { if($_POST[$i.'_field']!="") { $query = "ALTER TABLE ".$_GET['table']." ADD ".$_POST[$i.'_field']." "; $query .= $_POST[$i.'_type']." "; if(isset($_POST[$i.'_primarykey'])) $query .= "PRIMARY KEY "; if(isset($_POST[$i.'_notnull'])) $query .= "NOT NULL "; if($_POST[$i.'_defaultvalue']!="") { if($_POST[$i.'_type']=="INTEGER") $query .= "DEFAULT ".$_POST[$i.'_defaultvalue']." "; else $query .= "DEFAULT '".$_POST[$i.'_defaultvalue']."' "; } if($db->getVersion()==3) $result = $db->query($query, true); else $result = $db->query($query, false); if(!$result) $error = true; } } $completed = "Table '".$_GET['table']."' has been altered successfully."; break; /////////////////////////////////////////////// delete column case "column_delete": $pks = explode(":", $_GET['pk']); $str = $pks[0]; $query = "ALTER TABLE ".$_GET['table']." DROP ".$pks[0]; for($i=1; $iquery($query); if(!$result) $error = true; $completed = "Table '".$_GET['table']."' has been altered successfully."; break; /////////////////////////////////////////////// edit column case "column_edit": $query = "ALTER TABLE ".$_GET['table']." CHANGE ".$_POST['field_old']." ".$_POST['field']." ".$_POST['type']; $result = $db->query($query); if(!$result) $error = true; $completed = "Table '".$_GET['table']."' has been altered successfully."; break; /////////////////////////////////////////////// delete index case "index_delete": $query = "DROP INDEX ".$_GET['pk']; $result = $db->query($query); if(!$result) $error = true; $completed = "Index '".$_GET['pk']."' deleted.
".$query.""; break; /////////////////////////////////////////////// create index case "index_create": $num = $_POST['num']; $str = "CREATE "; if($_POST['duplicate']=="no") $str .= "UNIQUE "; $str .= "INDEX ".$_POST['name']." ON ".$_GET['table']." ("; $str .= $_POST['0_field'].$_POST['0_order']; for($i=1; $i<$num; $i++) { if($_POST[$i.'_field']!="--Ignore--") $str .= ", ".$_POST[$i.'_field'].$_POST[$i.'_order']; } $str .= ")"; $query = $str; $result = $db->query($query); if(!$result) $error = true; $completed = "Index created.
".$query.""; break; } } echo "
"; echo "
"; echo "

"; echo ""; echo " v".VERSION.""; echo ""; echo "

"; echo "
Change Database"; if(sizeof($databases)<10) //if there aren't a lot of databases, just show them as a list of links instead of drop down menu { for($i=0; $i".$databases[$i]['name'].""; else echo "".$databases[$i]['name'].""; if($i"; } } else //there are a lot of databases - show a drop down menu { echo "
"; echo " "; echo ""; echo "
"; } echo "
"; echo "
"; echo "".$currentDB['name'].""; echo ""; //Display list of tables $query = "SELECT name FROM sqlite_master WHERE type='table' ORDER BY name"; $result = $db->selectArray($query); $j=0; for($i=0; $i".$result[$i]['name']."
"; $j++; } } if($j==0) echo "No tables in database."; echo "
"; echo "
"; echo "
"; echo ""; echo "
"; echo "
"; echo "
"; echo "
"; //breadcrumb navigation echo "".$currentDB['name'].""; if(isset($_GET['table'])) echo " → ".$_GET['table'].""; echo "

"; //user has performed some action so show the resulting message if(isset($_GET['confirm'])) { echo "
"; echo "
"; if(isset($error) && $error) //an error occured during the action, so show an error message echo "An error occured. This may be a bug that needs to be reported at code.google.com/p/phpliteadmin/issues/list"; else //action was performed successfully - show success message echo $completed; echo "
"; if($_GET['action']=="row_delete" || $_GET['action']=="row_create" || $_GET['action']=="row_edit") echo "

Return"; else if($_GET['action']=="column_create" || $_GET['action']=="column_delete" || $_GET['action']=="column_edit" || $_GET['action']=="index_create" || $_GET['action']=="index_delete") echo "

Return"; else echo "

Return"; echo "
"; } //show the various tab views for a table if(!isset($_GET['confirm']) && isset($_GET['table']) && isset($_GET['action']) && ($_GET['action']=="table_export" || $_GET['action']=="table_import" || $_GET['action']=="table_sql" || $_GET['action']=="row_view" || $_GET['action']=="row_create" || $_GET['action']=="column_view" || $_GET['action']=="table_rename" || $_GET['action']=="table_search")) { echo "Browse"; echo "Structure"; echo "SQL"; echo "Search"; echo "Insert"; echo "Export"; echo "Import"; echo "Rename"; echo "Empty"; echo "Drop"; echo "
"; } //switch board for the page display if(isset($_GET['action']) && !isset($_GET['confirm'])) { echo "
"; switch($_GET['action']) { //table actions /////////////////////////////////////////////// create table case "table_create": echo "

Creating new table: '".$_POST['tablename']."'

"; if($_POST['tablefields']=="" || intval($_POST['tablefields'])<=0) echo "You must specify the number of table fields."; else if($_POST['tablename']=="") echo "You must specify a table name."; else { $num = intval($_POST['tablefields']); $name = $_POST['tablename']; echo "
"; echo ""; echo ""; echo ""; echo ""; $headings = array("Field", "Type", "Primary Key", "Autoincrement", "Not NULL", "Default Value"); for($k=0; $k" . $headings[$k] . ""; echo ""; for($i=0; $i<$num; $i++) { $tdWithClass = ""; echo $tdWithClass; echo ""; echo ""; echo $tdWithClass; echo ""; echo ""; echo $tdWithClass; echo " Yes"; echo ""; echo $tdWithClass; echo " Yes"; echo ""; echo $tdWithClass; echo " Yes"; echo ""; echo $tdWithClass; echo ""; echo ""; echo ""; } echo ""; echo ""; echo ""; echo "
"; echo "
"; echo " "; echo "Cancel"; echo "
"; echo "
"; } break; /////////////////////////////////////////////// perform SQL query on table case "table_sql": $isSelect = false; if(isset($_POST['query']) && $_POST['query']!="") { $delimiter = $_POST['delimiter']; $queryStr = stripslashes($_POST['queryval']); $query = explode($delimiter, $queryStr); //explode the query string into individual queries based on the delimiter for($i=0; $iselectArray($query[$i], "assoc"); } else { $isSelect = false; $result = $db->query($query[$i]); } $endTime = microtime(true); $time = round(($endTime - $startTime), 4); echo "
"; echo ""; if($isSelect && $result) { if($isSelect) { $affected = sizeof($result); echo "Showing ".$affected." row(s). "; } else { $affected = $db->getAffectedRows(); echo $affected." row(s) affected. "; } echo "(Query took ".$time." sec)
"; } else { echo "There is a problem with the syntax of your query "; echo "(Query was not executed)
"; } echo "".$query[$i].""; echo "

"; if($isSelect) { if(sizeof($result)>0) { $headers = array_keys($result[0]); echo ""; echo ""; for($j=0; $j"; echo $headers[$j]; echo ""; } echo ""; for($j=0; $j"; echo ""; for($z=0; $z"; } echo ""; } echo "


"; } } } } } else { $delimiter = ";"; $queryStr = "SELECT * FROM `".$_GET['table']."` WHERE 1"; } echo "
"; echo "Run SQL query/queries on database '".$db->getName()."'"; echo "
"; echo "
"; echo ""; echo "
"; echo "
"; echo "Fields
"; echo ""; echo ""; echo "
"; echo "
"; echo "Delimiter "; echo ""; echo "
"; break; /////////////////////////////////////////////// empty table case "table_empty": echo "
"; echo ""; echo "
"; echo "Are you sure you want to empty the table '".$_GET['table']."'?

"; echo " "; echo "Cancel"; echo "
"; break; /////////////////////////////////////////////// drop table case "table_drop": echo ""; echo ""; echo "
"; echo "Are you sure you want to drop the table '".$_GET['table']."'?

"; echo " "; echo "Cancel"; echo "
"; break; /////////////////////////////////////////////// export table case "table_export": echo ""; echo "
Export"; echo ""; echo " SQL"; echo "
"; echo "
Options"; echo " Export with structure [?]
"; echo " Export with data [?]
"; echo " Add DROP TABLE [?]
"; echo " Add TRANSACTION [?]
"; echo " Comments [?]
"; echo "
"; echo "
"; echo "

"; echo "
Save As"; echo ""; echo " "; echo "
"; echo "
"; break; /////////////////////////////////////////////// import table case "table_import": if(isset($_POST['import'])) { echo "
"; echo "Import was successful."; echo "

"; } echo "
"; echo "
File to import"; echo " SQL"; echo "

"; echo " "; echo "
"; break; /////////////////////////////////////////////// rename table case "table_rename": echo ""; echo ""; echo "Rename table '".$_GET['table']."' to "; echo "
"; break; /////////////////////////////////////////////// search table case "table_search": if(isset($_GET['done'])) { $query = "PRAGMA table_info('".$_GET['table']."')"; $result = $db->selectArray($query); $str = ""; $j = 0; $arr = array(); for($i=0; $iquote($value); $j++; } } $query = "SELECT * FROM ".$_GET['table']; if(sizeof($arr)>0) { $query .= " WHERE ".$arr[0]; for($i=1; $iselectArray($query, "assoc"); $endTime = microtime(true); $time = round(($endTime - $startTime), 4); echo "
"; echo ""; if($result) { $affected = sizeof($result); echo "Showing ".$affected." row(s). "; echo "(Query took ".$time." sec)
"; } else { echo "There is a problem with the syntax of your query "; echo "(Query was not executed)
"; } echo "".$query.""; echo "

"; if(sizeof($result)>0) { $headers = array_keys($result[0]); echo ""; echo ""; for($j=0; $j"; echo $headers[$j]; echo ""; } echo ""; for($j=0; $j"; echo ""; for($z=0; $z"; } echo ""; } echo "


"; echo "Do Another Search"; } } else { $query = "PRAGMA table_info('".$_GET['table']."')"; $result = $db->selectArray($query); echo "
"; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; for($i=0; $i"; $tdWithClassLeft = ""; echo $tdWithClassLeft; echo $field; echo ""; echo $tdWithClassLeft; echo $type; echo ""; echo $tdWithClassLeft; echo ""; echo ""; echo $tdWithClassLeft; if($type=="INTEGER" || $type=="REAL" || $type=="NULL") echo ""; else echo ""; echo ""; echo ""; } echo ""; echo ""; echo ""; echo "
FieldTypeOperatorValue
"; echo "
"; echo ""; echo "
"; echo "
"; } break; //row actions /////////////////////////////////////////////// view row case "row_view": if(!isset($_POST['startRow'])) $_POST['startRow'] = 0; if(isset($_POST['numRows'])) $_SESSION[COOKIENAME.'numRows'] = $_POST['numRows']; if(!isset($_SESSION[COOKIENAME.'numRows'])) $_SESSION[COOKIENAME.'numRows'] = 30; if(isset($_SESSION[COOKIENAME.'currentTable']) && $_SESSION[COOKIENAME.'currentTable']!=$_GET['table']) { unset($_SESSION[COOKIENAME.'sort']); unset($_SESSION[COOKIENAME.'order']); } $query = "SELECT Count(*) FROM ".$_GET['table']; $rowCount = $db->select($query); $rowCount = intval($rowCount[0]); $lastPage = intval($rowCount / $_SESSION[COOKIENAME.'numRows']); $remainder = intval($rowCount % $_SESSION[COOKIENAME.'numRows']); if($remainder==0) $remainder = $_SESSION[COOKIENAME.'numRows']; echo "
"; //previous button if($_POST['startRow']>0) { echo "
"; echo "
"; echo ""; echo " "; echo " "; echo "
"; echo "
"; echo "
"; echo "
"; echo ""; echo " "; echo " "; echo "
"; echo "
"; } //show certain number buttons echo "
"; echo "
"; echo " "; echo " "; echo "row(s) starting from record # "; if(intval($_POST['startRow']+$_SESSION[COOKIENAME.'numRows']) < $rowCount) echo ""; else echo ""; echo "
"; echo "
"; //next button if(intval($_POST['startRow']+$_SESSION[COOKIENAME.'numRows'])<$rowCount) { echo "
"; echo "
"; echo ""; echo " "; echo " "; echo "
"; echo "
"; echo "
"; echo "
"; echo ""; echo " "; echo " "; echo "
"; echo "
"; } echo "
"; echo "
"; if(!isset($_GET['sort'])) $_GET['sort'] = NULL; if(!isset($_GET['order'])) $_GET['order'] = NULL; $table = $_GET['table']; $numRows = $_SESSION[COOKIENAME.'numRows']; $startRow = $_POST['startRow']; if(isset($_GET['sort'])) { $_SESSION[COOKIENAME.'sort'] = $_GET['sort']; $_SESSION[COOKIENAME.'currentTable'] = $_GET['table']; } if(isset($_GET['order'])) { $_SESSION[COOKIENAME.'order'] = $_GET['order']; $_SESSION[COOKIENAME.'currentTable'] = $_GET['table']; } $_SESSION[COOKIENAME.'numRows'] = $numRows; $query = "SELECT *, ROWID FROM ".$table; $queryDisp = "SELECT * FROM ".$table; $queryAdd = ""; if(isset($_SESSION[COOKIENAME.'sort'])) $queryAdd .= " ORDER BY ".$_SESSION[COOKIENAME.'sort']; if(isset($_SESSION[COOKIENAME.'order'])) $queryAdd .= " ".$_SESSION[COOKIENAME.'order']; $queryAdd .= " LIMIT ".$startRow.", ".$numRows; $query .= $queryAdd; $queryDisp .= $queryAdd; $startTime = microtime(true); $arr = $db->selectArray($query); $endTime = microtime(true); $time = round(($endTime - $startTime), 4); $total = $db->numRows($table); if(sizeof($arr)>0) { echo "
"; echo "Showing rows ".$startRow." - ".($startRow + sizeof($arr)-1)." (".$total." total, Query took ".$time." sec)
"; echo "".$queryDisp.""; echo "

"; echo "
"; echo ""; $query = "PRAGMA table_info('".$table."')"; $result = $db->selectArray($query); $rowidColumn = sizeof($result); echo ""; echo ""; for($i=0; $i"; echo "".$result[$i][1].""; if(isset($_SESSION[COOKIENAME.'sort']) && $_SESSION[COOKIENAME.'sort']==$result[$i][1]) echo (($_SESSION[COOKIENAME.'order']=="ASC") ? " " : " "); echo ""; } echo ""; for($i=0; $i $pk will always be the last column in each row of the array because we are doing a "SELECT *, ROWID FROM ..." $pk = $arr[$i][$rowidColumn]; $tdWithClass = ""; echo $tdWithClass; echo ""; echo ""; echo $tdWithClass; // -g-> Here, we need to put the ROWID in as the link for both the edit and delete. echo "edit"; echo ""; echo $tdWithClass; echo "delete"; echo ""; for($j=0; $j although the inputs do not interpret HTML on the way "in", when we print the contents of the database the interpretation cannot be avoided. echo $db->formatString($arr[$i][$j]); echo ""; } echo ""; } echo "
"; echo "
"; $tdWithClassLeft = ""; echo "
"; echo "Check All / Uncheck All With selected: "; echo " "; echo ""; echo "
"; } else if($rowCount>0)//no rows - do nothing { echo "

There are no rows in the table for the range you selected."; } else { echo "

This table is empty. Click here to insert rows."; } break; /////////////////////////////////////////////// create row case "row_create": $fieldStr = ""; echo "
"; echo "Restart insertion with "; echo ""; echo " rows "; echo ""; echo "
"; echo "
"; $query = "PRAGMA table_info('".$_GET['table']."')"; $result = $db->selectArray($query); echo "
"; if(isset($_POST['num'])) $num = $_POST['num']; else $num = 1; echo ""; for($j=0; $j<$num; $j++) { if($j>0) echo " Ignore
"; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; for($i=0; $i"; $tdWithClassLeft = ""; echo $tdWithClassLeft; echo $field; echo ""; echo $tdWithClassLeft; echo $type; echo ""; echo $tdWithClassLeft; echo ""; echo ""; echo $tdWithClassLeft; if($type=="INTEGER" || $type=="REAL" || $type=="NULL") echo ""; else echo ""; echo ""; echo ""; } echo ""; echo ""; echo ""; echo "
FieldTypeFunctionValue
"; echo "
"; echo ""; echo "

"; } $fieldStr = substr($fieldStr, 1); echo ""; echo "
"; break; /////////////////////////////////////////////// edit or delete row case "row_editordelete": if(isset($_POST['check'])) $pks = $_POST['check']; else if(isset($_GET['pk'])) $pks = array($_GET['pk']); $str = $pks[0]; $pkVal = $pks[0]; for($i=1; $i"; echo "Error: You did not select anything."; echo "
"; echo "

Return"; } else { if((isset($_POST['type']) && $_POST['type']=="edit") || (isset($_GET['type']) && $_GET['type']=="edit")) //edit { echo "
"; $query = "PRAGMA table_info('".$_GET['table']."')"; $result = $db->selectArray($query); //build the POST array of fields $fieldStr = $result[0][1]; for($j=1; $j"; for($j=0; $j"; echo ""; echo "Field"; echo "Type"; echo "Function"; echo "Value"; echo ""; for($i=0; $i"; $tdWithClassLeft = ""; echo ""; echo $tdWithClass; echo $field; echo ""; echo $tdWithClass; echo $type; echo ""; echo $tdWithClassLeft; echo ""; echo ""; echo $tdWithClassLeft; if($type=="INTEGER" || $type=="REAL" || $type=="NULL") echo ""; else echo ""; echo ""; echo ""; } echo ""; echo ""; echo " "; echo "Cancel"; echo ""; echo ""; echo ""; echo "
"; } echo ""; } else //delete { echo "
"; echo "
"; echo "Are you sure you want to delete row(s) ".$str." from table '".$_GET['table']."'?

"; echo " "; echo "Cancel"; echo "
"; } } break; //column actions /////////////////////////////////////////////// view column case "column_view": $query = "PRAGMA table_info('".$_GET['table']."')"; $result = $db->selectArray($query); echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; for($i=0; $i"; $tdWithClassLeft = ""; echo $tdWithClass; echo ""; echo ""; echo $tdWithClass; echo "delete"; echo ""; echo $tdWithClass; echo $colVal; echo ""; echo $tdWithClassLeft; echo $fieldVal; echo ""; echo $tdWithClassLeft; echo $typeVal; echo ""; echo $tdWithClassLeft; echo $notnullVal; echo ""; echo $tdWithClassLeft; echo $defaultVal; echo ""; echo $tdWithClassLeft; echo $primarykeyVal; echo ""; echo ""; } echo "
"; echo "Column #FieldTypeNot NullDefault ValuePrimary Key
"; echo "
"; echo "Check All / Uncheck All With selected: "; echo " "; echo ""; echo ""; echo "
"; echo "
"; echo "
"; echo ""; echo "Add field(s) at end of table "; echo "
"; echo "


"; //$query = "SELECT * FROM sqlite_master WHERE type='index' AND tbl_name='".$_GET['table']."'"; $query = "PRAGMA index_list(".$_GET['table'].")"; $result = $db->selectArray($query); if(sizeof($result)>0) { echo "

Indexes:

"; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; for($i=0; $iselectArray($query); $span = sizeof($info); $tdWithClass = ""; echo $tdWithClassSpan; echo "delete"; echo ""; echo $tdWithClassLeftSpan; echo $result[$i]['name']; echo ""; echo $tdWithClassLeftSpan; echo $unique; echo ""; for($j=0; $j<$span; $j++) { if($j!=0) echo ""; echo $tdWithClassLeft; echo $info[$j]['seqno']; echo ""; echo $tdWithClassLeft; echo $info[$j]['cid']; echo ""; echo $tdWithClassLeft; echo $info[$j]['name']; echo ""; echo ""; } } echo "
"; echo "NameUniqueSeq. No.Column #Field
"; $tdWithClassLeft = ""; $tdWithClassSpan = ""; $tdWithClassLeftSpan = ""; echo "
"; } echo "
"; echo ""; echo "
"; echo "Create an index on columns "; echo "
"; echo "
"; break; /////////////////////////////////////////////// create column case "column_create": echo "

Adding new field(s) to table '".$_POST['tablename']."'

"; if($_POST['tablefields']=="" || intval($_POST['tablefields'])<=0) echo "You must specify the number of table fields."; else if($_POST['tablename']=="") echo "You must specify a table name."; else { $num = intval($_POST['tablefields']); $name = $_POST['tablename']; echo "
"; echo ""; echo ""; echo ""; echo ""; $headings = array("Field", "Type", "Primary Key", "Autoincrement", "Not NULL", "Default Value"); for($k=0; $k" . $headings[$k] . ""; echo ""; for($i=0; $i<$num; $i++) { $tdWithClass = ""; echo $tdWithClass; echo ""; echo ""; echo $tdWithClass; echo ""; echo ""; echo $tdWithClass; echo " Yes"; echo ""; echo $tdWithClass; echo " Yes"; echo ""; echo $tdWithClass; echo " Yes"; echo ""; echo $tdWithClass; echo ""; echo ""; echo ""; } echo ""; echo ""; echo ""; echo "
"; echo "
"; echo " "; echo "Cancel"; echo "
"; echo "
"; } break; /////////////////////////////////////////////// delete column case "column_delete": if(isset($_POST['check'])) $pks = $_POST['check']; else if(isset($_GET['pk'])) $pks = array($_GET['pk']); $str = $pks[0]; $pkVal = $pks[0]; for($i=1; $i"; echo "Error: You did not select anything."; echo "
"; echo "

Return"; } else { echo "
"; echo "
"; echo "Are you sure you want to delete column(s) ".$str." from table '".$_GET['table']."'?

"; echo " "; echo "Cancel"; echo "
"; } break; /////////////////////////////////////////////// edit column case "column_edit": //this section will contain the code for editing a column break; /////////////////////////////////////////////// delete index case "index_delete": echo ""; echo "
"; echo "Are you sure you want to delete index '".$_GET['pk']."'?

"; echo " "; echo "Cancel"; echo "
"; echo "
"; break; /////////////////////////////////////////////// create index case "index_create": echo "

Creating new index on table '".$_POST['tablename']."'

"; if($_POST['numcolumns']=="" || intval($_POST['numcolumns'])<=0) echo "You must specify the number of table fields."; else if($_POST['tablename']=="") echo "You must specify a table name."; else { echo "
"; $num = intval($_POST['numcolumns']); $query = "PRAGMA table_info('".$_POST['tablename']."')"; $result = $db->selectArray($query); echo "
Define index properties"; echo "Index name:
"; echo "Duplicate values: "; echo "
"; echo "
"; echo "
"; echo "
Define index columns"; for($i=0; $i<$num; $i++) { echo " "; echo "
"; } echo "
"; echo "

"; echo ""; echo " "; echo "Cancel"; echo "
"; } break; } echo "
"; } $view = "structure"; if(!isset($_GET['table']) && !isset($_GET['confirm']) && (!isset($_GET['action']) || (isset($_GET['action']) && $_GET['action']!="table_create"))) //the absence of these fields means we are viewing the database homepage { if(isset($_GET['view'])) $view = $_GET['view']; else $view = "structure"; echo "Structure"; echo "SQL"; echo "Export"; echo "Import"; echo "Vacuum"; echo "
"; echo "
"; if($view=="structure") //database structure - view of all the tables { $query = "SELECT sqlite_version() AS sqlite_version"; $queryVersion = $db->select($query); $realVersion = $queryVersion['sqlite_version']; echo "Database name: ".$db->getName()."
"; echo "Path to database: ".$db->getPath()."
"; echo "Size of database: ".$db->getSize()."
"; echo "Database last modified: ".$db->getDate()."
"; echo "SQLite version: ".$realVersion."
"; echo "SQLite extension: ".$db->getType()."
"; echo "PHP version: ".phpversion()."

"; $query = "SELECT name FROM sqlite_master WHERE type='table' ORDER BY name"; $result = $db->selectArray($query); $j = 0; for($i=0; $i
"; else { echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; $totalRecords = 0; for($i=0; $inumRows($result[$i]['name']); $totalRecords += $records; $tdWithClass = ""; echo $tdWithClassLeft; echo "".$result[$i]['name']."
"; echo ""; echo $tdWithClass; echo "Browse"; echo ""; echo $tdWithClass; echo "Structure"; echo ""; echo $tdWithClass; echo "SQL"; echo ""; echo $tdWithClass; echo "Search"; echo ""; echo $tdWithClass; echo "Insert"; echo ""; echo $tdWithClass; echo "Export"; echo ""; echo $tdWithClass; echo "Import"; echo ""; echo $tdWithClass; echo "Rename"; echo ""; echo $tdWithClass; echo "Empty"; echo ""; echo $tdWithClass; echo "Drop"; echo ""; echo $tdWithClass; echo $records; echo ""; echo ""; } } echo ""; echo ""; echo ""; echo ""; echo "
TableActionRecords
"; $tdWithClassLeft = ""; echo "
".sizeof($result)." table(s) total".$totalRecords."
"; echo "
"; } echo "
"; echo "Create new table on database '".$db->getName()."'"; echo "
"; echo "Name: "; echo "Number of Fields: "; echo ""; echo "
"; echo "
"; } else if($view=="sql") //database SQL editor { $isSelect = false; if(isset($_POST['query']) && $_POST['query']!="") { $delimiter = $_POST['delimiter']; $queryStr = stripslashes($_POST['queryval']); $query = explode($delimiter, $queryStr); //explode the query string into individual queries based on the delimiter for($i=0; $iselectArray($query[$i], "assoc"); } else { $isSelect = false; $result = $db->query($query[$i]); } $endTime = microtime(true); $time = round(($endTime - $startTime), 4); echo "
"; echo ""; if($isSelect && $result) { if($isSelect) { $affected = sizeof($result); echo "Showing ".$affected." row(s). "; } else { $affected = $db->getAffectedRows(); echo $affected." row(s) affected. "; } echo "(Query took ".$time." sec)
"; } else { echo "There is a problem with the syntax of your query "; echo "(Query was not executed)
"; } echo "".$query[$i].""; echo "

"; if($isSelect) { if(sizeof($result)>0) { $headers = array_keys($result[0]); echo ""; echo ""; for($j=0; $j"; echo $headers[$j]; echo ""; } echo ""; for($j=0; $j"; echo ""; for($z=0; $z"; } echo ""; } echo "


"; } } } } } else { $delimiter = ";"; $queryStr = ""; } echo "
"; echo "Run SQL query/queries on database '".$db->getName()."'"; echo "
"; echo ""; echo "Delimiter "; echo ""; echo "
"; } else if($view=="vacuum") { if(isset($_POST['vacuum'])) { $query = "VACUUM"; $db->query($query); echo "
"; echo "The database, '".$db->getName()."', has been VACUUMed."; echo "

"; } echo "
"; echo "Large databases sometimes need to be VACUUMed to reduce their footprint on the server. Click the button below to VACUUM the database, '".$db->getName()."'."; echo "

"; echo ""; echo "
"; } else if($view=="export") { echo "
"; echo "
Export"; echo ""; echo "

"; echo " SQL"; echo "
"; echo "
Options"; echo " Export with structure [?]
"; echo " Export with data [?]
"; echo " Add DROP TABLE [?]
"; echo " Add TRANSACTION [?]
"; echo " Comments [?]
"; echo "
"; echo "
"; echo "

"; echo "
Save As"; echo ""; echo " "; echo "
"; echo "
"; } else if($view=="import") { if(isset($_POST['import'])) { echo "
"; echo "Import was successful."; echo "

"; } echo "
"; echo "
File to import"; echo " SQL"; echo "

"; echo " "; echo "
"; } echo "
"; } echo "
"; $endTimeTot = microtime(true); //get the current time at this point in the execution $timeTot = round(($endTimeTot - $startTimeTot), 4); //calculate the total time for page load echo "Powered by ".PROJECT." | Page generated in ".$timeTot." seconds."; echo ""; echo ""; $db->close(); //close the database } echo ""; echo ""; ?>