. // /////////////////////////////////////////////////////////////////////////// //please report any bugs you encounter to http://code.google.com/p/phpliteadmin/issues/list //BEGIN USER-DEFINED VARIABLES ////////////////////////////// //password to gain access $password = "badaap"; //directory relative to this file to search for databases (if false, manually list databases in the $databases variable) $directory = "."; //whether or not to scan the subdirectories of the above directory infinitely deep $subdirectories = false; //if the above $directory variable is set to false, you must specify the databases manually in an array as the next variable //if any of the databases do not exist as they are referenced by their path, they will be created automatically $databases = array ( array ( "path"=> "database1.sqlite", "name"=> "Database 1" ), array ( "path"=> "database2.sqlite", "name"=> "Database 2" ) ); //a list of custom functions that can be applied to columns in the databases //make sure to define every function below if it is not a core PHP function $custom_functions = array('md5', 'md5rev', 'sha1', 'sha1rev', 'time', 'mydate', 'strtotime', 'myreplace'); //define all the non-core custom functions function md5rev($value) { return strrev(md5($value)); } function sha1rev($value) { return strrev(sha1($value)); } function mydate($value) { return date("g:ia n/j/y", intval($value)); } function myreplace($value) { return ereg_replace("[^A-Za-z0-9]", "", strval($value)); } //changing the following variable allows multiple phpLiteAdmin installs to work under the same domain. $cookie_name = 'pla3412'; //whether or not to put the app in debug mode where errors are outputted $debug = false; //////////////////////////// //END USER-DEFINED VARIABLES //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! //there is no reason for the average user to edit anything below this comment //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 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 if($debug==true) { 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.9.1"); 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)); //accepted db extensions $exts = array("sqlite", "sqlite3", "db", "db3"); define("EXTENSIONS", serialize($exts)); //available SQLite functions array (don't add anything here or there will be problems) $functions = array("abs", "hex", "length", "lower", "ltrim", "random", "round", "rtrim", "trim", "typeof", "upper"); define("FUNCTIONS", serialize($functions)); define("CUSTOM_FUNCTIONS", serialize($custom_functions)); //function that allows SQL delimiter to be ignored inside comments or strings function explode_sql($delimiter, $sql) { $ign = array('"' => '"', "'" => "'", "/*" => "*/", "--" => "\n"); // Ignore sequences. $out = array(); $last = 0; $slen = strlen($sql); $dlen = strlen($delimiter); $i = 0; while($i < $slen) { // Split on delimiter if($slen - $i >= $dlen && substr($sql, $i, $dlen) == $delimiter) { array_push($out, substr($sql, $last, $i - $last)); $last = $i + $dlen; $i += $dlen; continue; } // Eat comments and string literals foreach($ign as $start => $end) { $ilen = strlen($start); if($slen - $i >= $ilen && substr($sql, $i, $ilen) == $start) { $i+=strlen($start); $elen = strlen($end); while($i < $slen) { if($slen - $i >= $elen && substr($sql, $i, $elen) == $end) { // SQL comment characters can be escaped by doubling the character. This recognizes and skips those. if($start == $end && $slen - $i >= $elen*2 && substr($sql, $i, $elen*2) == $end.$end) { $i += $elen * 2; continue; } else { $i += $elen; continue 3; } } $i++; } continue 2; } } $i++; } if($last < $slen) array_push($out, substr($sql, $last, $slen - $last)); return $out; } //function to scan entire directory tree and subdirectories function dir_tree($dir) { $path = ''; $stack[] = $dir; while($stack) { $thisdir = array_pop($stack); if($dircont = scandir($thisdir)) { $i=0; while(isset($dircont[$i])) { if($dircont[$i] !== '.' && $dircont[$i] !== '..') { $current_file = "{$thisdir}/{$dircont[$i]}"; if(is_file($current_file)) { $path[] = "{$thisdir}/{$dircont[$i]}"; } elseif (is_dir($current_file)) { $path[] = "{$thisdir}/{$dircont[$i]}"; $stack[] = $current_file; } } $i++; } } } return $path; } //the function echo the help [?] links to the documentation function helpLink($name) { return "[?]"; } //user is deleting a database if(isset($_GET['database_delete'])) { $dbpath = $_POST['database_delete']; unlink($dbpath); $_SESSION[COOKIENAME.'currentDB'] = 0; } //user is renaming a database if(isset($_GET['database_rename'])) { $oldpath = $_POST['oldname']; $newpath = $_POST['newname']; if(!file_exists($newpath)) { copy($oldpath, $newpath); unlink($oldpath); $justrenamed = true; } else { $dbexists = true; } } //user is creating a new Database if(isset($_POST['new_dbname'])) { $str = preg_replace('@[^\w-.]@','', $_POST['new_dbname']); $dbname = $str; $dbpath = $str; $info = pathinfo($dbpath); if(!isset($info['extension'])) $dbpath = $dbpath.".".$exts[0]; else { if(!in_array(strtolower($info['extension']), $exts)) { $dbpath = $dbpath.".".$exts[0]; } } $tdata = array(); $tdata['name'] = $dbname; $tdata['path'] = $directory."/".$dbpath; $td = new Database($tdata); } //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 { if($subdirectories===true) $arr = dir_tree($directory); else $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(); } } // 22 August 2011: gkf added this function to support display of // default values in the form used to INSERT new data. function deQuoteSQL($s) { return trim(trim($s), "'"); } // // 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; protected $fns; public function __construct($data) { $this->data = $data; $this->fns = array(); try { 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"; $cfns = unserialize(CUSTOM_FUNCTIONS); for($i=0; $idb->sqliteCreateFunction($cfns[$i], $cfns[$i], 1); $this->addUserFunction($cfns[$i]); } 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) { $cfns = unserialize(CUSTOM_FUNCTIONS); for($i=0; $idb->createFunction($cfns[$i], $cfns[$i], 1); $this->addUserFunction($cfns[$i]); } $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) { $cfns = unserialize(CUSTOM_FUNCTIONS); for($i=0; $idb->createFunction($cfns[$i], $cfns[$i], 1); $this->addUserFunction($cfns[$i]); } $this->type = "SQLiteDatabase"; break; } default: $this->showError(); exit(); } } catch(Exception $e) { $this->showError(); exit(); } } public function getUserFunctions() { return $this->fns; } public function addUserFunction($name) { array_push($this->fns, $name); } public function getError() { if($this->type=="PDO") { $e = $this->db->errorInfo(); return $e[2]; } else if($this->type=="SQLite3") { return $this->db->lastErrorMsg(); } else { return sqlite_error_string($this->db->lastError()); } } 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) { $error = "Unknown error."; if($this->type=="PDO") { $success = $this->db->exec($query); } else if($this->type=="SQLite3") { $success = $this->db->exec($query, $error); } else { $success = $this->db->queryExec($query, $error); } if(!$success) { return "Error in query: '".$error."'"; } else { return true; } } //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 sqlite_escape_string($value); } } //correctly format a string value from a table before showing it public function formatString($value) { return htmlspecialchars(stripslashes($value)); } //import sql public function import_sql($query) { return $this->multiQuery($query); } //import csv public function import_csv($filename, $separator, $table) { //to do: CSV import - someone do it!!!!!! return "CSV import not implemented yet. Anyone up for the task?"; } //export csv public function export_csv($tables, $field_terminate, $field_enclosed, $field_escaped, $line_terminated, $null, $crlf, $fields_in_first_row) { $field_enclosed = stripslashes($field_enclosed); $query = "SELECT * FROM sqlite_master WHERE type='table' OR type='index' ORDER BY type DESC"; $result = $this->selectArray($query); for($i=0; $iselectArray($query); $cols = array(); for($z=0; $zselectArray($query, "assoc"); for($z=0; $zgetPath()."\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'])) { if($_POST['export_type']=="sql") { 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_sql($tables, $drop, $structure, $data, $transaction, $comments); } else if($_POST['export_type']=="csv") { header("Content-type: application/csv"); header('Content-Disposition: attachment; filename="'.$_POST['filename'].'.'.$_POST['export_type'].'";'); header("Pragma: no-cache"); header("Expires: 0"); if(isset($_POST['tables'])) $tables = $_POST['tables']; else { $tables = array(); $tables[0] = $_POST['single_table']; } $field_terminate = $_POST['export_csv_fieldsterminated']; $field_enclosed = $_POST['export_csv_fieldsenclosed']; $field_escaped = $_POST['export_csv_fieldsescaped']; $line_terminated = $_POST['export_csv_linesterminated']; $null = $_POST['export_csv_replacenull']; $crlf = isset($_POST['export_csv_crlf']); $fields_in_first_row = isset($_POST['export_csv_fieldnames']); $db = new Database($databases[$_SESSION[COOKIENAME.'currentDB']]); echo $db->export_csv($tables, $field_terminate, $field_enclosed, $field_escaped, $line_terminated, $null, $crlf, $fields_in_first_row); } exit(); } //user is importing a file if(isset($_POST['import'])) { $db = new Database($databases[$_SESSION[COOKIENAME.'currentDB']]); if($_POST['import_type']=="sql") { $data = file_get_contents($_FILES["file"]["tmp_name"]); $importSuccess = $db->import_sql($data); } else { $importSuccess = $db->import_csv($_FILES["file"]["tmp_name"], $_POST['import_csv_separator'], $_POST['single_table']); } } // here begins the HTML. ?> <?php echo PROJECT ?> "; } if(isset($_GET['help'])) //this page is used as the popup help section { //help section array $help = array ( 'SQLite Library Extensions' => 'phpLiteAdmin uses PHP library extensions that allow interaction with SQLite databases. Currently, phpLiteAdmin supports PDO, SQLite3, and SQLiteDatabase. Both PDO and SQLite3 deal with version 3 of SQLite, while SQLiteDatabase deals with version 2. So, if your PHP installation includes more than one SQLite library extension, PDO and SQLite3 will take precedence to make use of the better technology. However, if you have existing databases that are of version 2 of SQLite, phpLiteAdmin will be forced to use SQLiteDatabase for only those databases. Not all databases need to be of the same version. During the database creation, however, the most advanced extension will be used.', 'Creating a New Database' => 'When you create a new database, the name you entered will be appended with the appropriate file extension (.db, .db3, .sqlite, etc.) if you do not include it yourself. The database will be created in the directory you specified as the $directory variable.', 'Tables vs. Views' => 'On the main database page, there is a list of tables and views. Since views are read-only, certain operations will be disabled. These disabled operations will be apparent by their omission in the location where they should appear on the row for a view. If you want to change the data for a view, you need to drop that view and create a new view with the appropriate SELECT statement that queries other existing tables. For more information, see http://en.wikipedia.org/wiki/View_(database)', 'Writing a Select Statement for a New View' => 'When you create a new view, you must write an SQL SELECT statement that it will use as its data. A view is simply a read-only table that can be accessed and queried like a regular table, except it cannot be modified through insertion, column editing, or row editing. It is only used for conveniently fetching data.', 'Export Structure to SQL File' => 'During the process for exporting to an SQL file, you may choose to include the queries that create the table and columns.', 'Export Data to SQL File' => 'During the process for exporting to an SQL file, you may choose to include the queries that populate the table(s) with the current records of the table(s).', 'Add Drop Table to Exported SQL File' => 'During the process for exporting to an SQL file, you may choose to include queries to DROP the existing tables before adding them so that problems do not occur when trying to create tables that already exist.', 'Add Transaction to Exported SQL File' => 'During the process for exporting to an SQL file, you may choose to wrap the queries around a TRANSACTION so that if an error occurs at any time during the importation process using the exported file, the database can be reverted to its previous state, preventing partially updated data from populating the database.', 'Add Comments to Exported SQL File' => 'During the process for exporting to an SQL file, you may choose to include comments that explain each step of the process so that a human can better understand what is happening.', ); ?>
"; echo "".PROJECT." v".VERSION." Help Documentation

"; foreach((array)$help as $key => $val) { echo "".$key."
"; } echo "
"; echo "

"; foreach((array)$help as $key => $val) { echo "
"; echo "".$key.""; echo "
"; echo $val; echo "
"; echo "Back to Top"; echo "
"; } ?> "; 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 ""; 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 { if($directory!==false && is_writable($directory)) { echo "
"; echo "Welcome to phpLiteAdmin. It appears that you have selected to scan a directory for databases to manage. However, phpLiteAdmin could not find any valid SQLite databases. You may use the form below to create your first database."; echo "
"; echo "
Create New Database"; echo "
"; echo " "; echo "
"; echo "
"; } else { echo "
"; echo "Error: The directory you specified does not contain any existing databases to manage, and the directory is not writable. This means you can't create any new databases using phpLiteAdmin. Either make the directory writable or manually upload databases to the directory."; 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 NOT NULL "; if(!isset($_POST[$i.'_primarykey']) && 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; /////////////////////////////////////////////// create view case "view_create": $query = "CREATE VIEW ".$_POST['viewname']." AS ".stripslashes($_POST['select']); $result = $db->query($query); if(!$result) $error = true; $completed = "View '".$_POST['viewname']."' has been created.
".$query.""; break; /////////////////////////////////////////////// drop table case "table_drop": $query = "DROP TABLE ".$_POST['tablename']; $db->query($query); $completed = "Table '".$_POST['tablename']."' has been dropped."; break; /////////////////////////////////////////////// drop view case "view_drop": $query = "DROP VIEW ".$_POST['viewname']; $db->query($query); $completed = "View '".$_POST['viewname']."' 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; $query = "PRAGMA table_info('".$_GET['table']."')"; $result = $db->selectArray($query); for($i=0; $i<$num; $i++) { if(!isset($_POST[$i.":ignore"])) { $query = "INSERT INTO ".$_GET['table']." ("; for($j=0; $jquote($value); else if(($type=="INTEGER" || $type=="REAL") && $null==false && $value=="") $query .= "NULL"; else if($null==true) $query .= "NULL"; else $query .= $db->quote($value); if($function!="") $query .= ")"; $query .= ","; } $query = substr($query, 0, sizeof($query)-2); $query .= ")"; $result1 = $db->query($query); if(!$result1) $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']); $z = 0; $query = "PRAGMA table_info('".$_GET['table']."')"; $result = $db->selectArray($query); if(isset($_POST['new_row'])) $completed = ""; else $completed = sizeof($pks)." row(s) affected.

"; for($i=0; $iquote($value); else if(($type=="INTEGER" || $type=="REAL") && $null==false && $value=="") $query .= "NULL"; else if($null==true) $query .= "NULL"; else $query .= $db->quote($value); if($function!="") $query .= ")"; $query .= ","; } $query = substr($query, 0, sizeof($query)-2); $query .= ")"; $result1 = $db->query($query); if(!$result1) $error = true; $z++; } else { $query = "UPDATE ".$_GET['table']." SET "; for($j=0; $jquote($_POST[$pks[$i].":".$fields[$j]]); if($function!="") $query .= ")"; $query .= ", "; } $query = substr($query, 0, sizeof($query)-3); $query .= " WHERE ROWID = ".$pks[$i]; $result1 = $db->query($query); if(!$result1) { $error = true; } } $completed .= "".$query."
"; } if(isset($_POST['new_row'])) $completed = $z." row(s) inserted.

".$completed; 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['oldvalue']." ".$_POST['0_field']." ".$_POST['0_type']; $result = $db->query($query); if(!$result) $error = true; $completed = "Table '".$_GET['table']."' has been altered successfully."; break; /////////////////////////////////////////////// delete trigger case "trigger_delete": $query = "DROP TRIGGER ".$_GET['pk']; $result = $db->query($query); if(!$result) $error = true; $completed = "Trigger '".$_GET['pk']."' deleted.
".$query.""; 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 trigger case "trigger_create": $str = "CREATE TRIGGER ".$_POST['trigger_name']; if($_POST['beforeafter']!="") $str .= " ".$_POST['beforeafter']; $str .= " ".$_POST['event']." ON ".$_GET['table']; if(isset($_POST['foreachrow'])) $str .= " FOR EACH ROW"; if($_POST['whenexpression']!="") $str .= " WHEN ".stripslashes($_POST['whenexpression']); $str .= " BEGIN"; $str .= " ".stripslashes($_POST['triggersteps']); $str .= " END"; $query = $str; $result = $db->query($query); if(!$result) $error = true; $completed = "Trigger created.
".$query.""; break; /////////////////////////////////////////////// create index case "index_create": $num = $_POST['num']; if($_POST['name']=="") { $completed = "Index name must not be blank."; } else if($_POST['0_field']=="") { $completed = "You must specify at least one index column."; } else { $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']!="") $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 ""; 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 type, name FROM sqlite_master WHERE type='table' OR type='view' ORDER BY name"; $result = $db->selectArray($query); $j=0; for($i=0; $i[table] [view] ".$result[$i]['name']."
"; $j++; } } if($j==0) echo "No tables in database."; echo "
"; if($directory!==false && is_writable($directory)) { echo "
Create New Database ".helpLink("Creating a New Database").""; echo "
"; echo " "; echo "
"; 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 "Error: ".$db->getError().".
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" || $_GET['action']=="trigger_delete" || $_GET['action']=="trigger_create") 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" || $_GET['action']=="table_triggers")) { if(!isset($_GET['view'])) { echo "Browse"; echo "Structure"; echo "SQL"; echo "Search"; echo "Insert"; echo "Export"; echo "Import"; echo "Rename"; echo "Empty"; echo "Drop"; echo "
"; } else { echo "Browse"; echo "Structure"; echo "SQL"; echo "Search"; echo "Export"; 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": $query = "SELECT name FROM sqlite_master WHERE type='table' AND name='".$_POST['tablename']."'"; $results = $db->selectArray($query); if(sizeof($results)>0) $exists = true; else $exists = false; 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 if($exists) echo "Table of the same name already exists."; 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_sql($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($result!==false) { 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()."'"; if(!isset($_GET['view'])) echo "
"; else 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; /////////////////////////////////////////////// drop view case "view_drop": echo ""; echo ""; echo "
"; echo "Are you sure you want to drop the view '".$_GET['table']."'?

"; echo " "; echo "Cancel"; echo "
"; break; /////////////////////////////////////////////// export table case "table_export": echo ""; echo "
Export"; echo ""; echo " SQL"; echo "
CSV"; echo "
"; echo "
Options"; echo " Export with structure ".helpLink("Export Structure to SQL File")."
"; echo " Export with data ".helpLink("Export Data to SQL File")."
"; echo " Add DROP TABLE ".helpLink("Add Drop Table to Exported SQL File")."
"; echo " Add TRANSACTION ".helpLink("Add Transaction to Exported SQL File")."
"; echo " Comments ".helpLink("Add Comments to Exported SQL File")."
"; echo "
"; echo ""; echo "
"; echo "

"; echo "
Save As"; echo ""; $file = pathinfo($db->getPath()); $name = $file['filename']; echo " "; echo "
"; echo "
"; break; /////////////////////////////////////////////// import table case "table_import": if(isset($_POST['import'])) { echo "
"; if($importSuccess===true) echo "Import was successful."; else echo $importSuccess; echo "

"; } echo "
"; echo "
Import into ".$_GET['table'].""; echo " SQL"; echo "
CSV"; echo "
"; echo "
Options"; echo "No options"; echo "
"; echo ""; echo "
"; echo "

"; echo "
File to import"; 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!==false) { $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 "


"; } if(!isset($_GET['view'])) echo "Do Another Search"; else echo "Do Another Search"; } else { $query = "PRAGMA table_info('".$_GET['table']."')"; $result = $db->selectArray($query); if(!isset($_GET['view'])) echo "
"; else 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']); } if(isset($_POST['viewtype'])) { $_SESSION[COOKIENAME.'viewtype'] = $_POST['viewtype']; } $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 " as a "; 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 "

"; if(isset($_GET['view'])) { echo "'".$_GET['table']."' is a view, which means it is a SELECT statement treated as a read-only table. You may not edit or insert records. http://en.wikipedia.org/wiki/View_(database)"; echo "

"; } $query = "PRAGMA table_info('".$table."')"; $result = $db->selectArray($query); $rowidColumn = sizeof($result); if(!isset($_SESSION[COOKIENAME.'viewtype']) || $_SESSION[COOKIENAME.'viewtype']=="table") { echo "
"; echo ""; echo ""; if(!isset($_GET['view'])) echo ""; for($i=0; $i"; if(!isset($_GET['view'])) 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 = ""; if(!isset($_GET['view'])) { 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. // di - i don't understand how SQLite returns null values. I played around with the conditional here and couldn't get empty strings to differeniate from actual null values... if($arr[$i][$j]==NULL) echo "NULL"; else echo $db->formatString($arr[$i][$j]); echo ""; } echo ""; } echo "
"; $tdWithClassLeft = ""; echo "
"; if(!isset($_GET['view'])) { echo "Check All / Uncheck All With selected: "; echo " "; echo ""; } echo "
"; } else { if(!isset($_SESSION[COOKIENAME.$_GET['table'].'chartlabels'])) { for($i=0; $i
If you can read this, it means the chart could not be generated. The data you are trying to view may not be appropriate for a chart.
Chart Settings"; echo "
"; echo "Chart Type: "; echo "

"; echo "Labels: "; echo "

"; echo "Values: "; echo "

"; echo ""; echo "
"; echo "
"; echo "
"; //end chart view } } 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 ""; echo ""; for($i=0; $i"; $tdWithClassLeft = ""; echo $tdWithClassLeft; echo $field; echo ""; echo $tdWithClassLeft; echo $type; echo ""; echo $tdWithClassLeft; echo ""; echo ""; //we need to have a column dedicated to nulls -di echo $tdWithClassLeft; if($result[$i][3]==0) { if($result[$i][4]==NULL) echo ""; else echo ""; } echo ""; echo $tdWithClassLeft; // 22 August 2011: gkf fixed bug #55. The form is now prepopulated with the default values // so that the insert proceeds normally. // 22 August 2011: gkf fixed bug #53. The form now displays more of the text. // 19 October 2011: di fixed the bug caused by the previous fix where the null column does not exist anymore $type = strtolower($type); if($scalarField) echo ""; else echo ""; echo ""; echo ""; } echo ""; echo ""; echo ""; echo "
FieldTypeFunctionNullValue
"; 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 "Null"; 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($result[$i][3]==0) { if($value==NULL) echo ""; else echo ""; } echo ""; echo $tdWithClassLeft; if($type=="INTEGER" || $type=="REAL" || $type=="NULL") echo ""; else echo ""; 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 ""; if(!isset($_GET['view'])) echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; for($i=0; $i"; $tdWithClassLeft = ""; if(!isset($_GET['view'])) { echo $tdWithClass; echo ""; echo ""; echo $tdWithClass; echo "edit"; 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 "
Column #FieldTypeNot NullDefault ValuePrimary Key
"; echo "
"; if(!isset($_GET['view'])) { echo "Check All / Uncheck All With selected: "; echo " "; echo ""; echo ""; } echo "
"; if(!isset($_GET['view'])) { echo "
"; echo "
"; echo ""; echo "Add field(s) at end of table "; echo "
"; } $query = "SELECT sql FROM sqlite_master WHERE name='".$_GET['table']."'"; $master = $db->selectArray($query); echo "
"; if(!isset($_GET['view'])) $typ = "table"; else $typ = "view"; echo "
"; echo "
"; echo "Query used to create this ".$typ."
"; echo "".$master[0]['sql'].""; echo "
"; echo "
"; if(!isset($_GET['view'])) { 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 "


"; } $query = "SELECT * FROM sqlite_master WHERE type='trigger' AND tbl_name='".$_GET['table']."' ORDER BY name"; $result = $db->selectArray($query); //print_r($result); if(sizeof($result)>0) { echo "

Triggers:

"; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; for($i=0; $i"; echo ""; echo $tdWithClass; echo "delete"; echo ""; echo $tdWithClass; echo $result[$i]['name']; echo ""; echo $tdWithClass; echo $result[$i]['sql']; echo ""; } echo "
"; echo "NameSQL


"; } echo "
"; echo ""; echo "
"; echo "Create an index on columns "; echo "
"; echo "
"; echo "
"; echo ""; echo "
"; echo "Create a new trigger "; 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": echo "

Editing column '".$_GET['pk']."' on table '".$_GET['table']."'

"; echo "Due to the limitations of SQLite, only the field name and data type can be modified.

"; if(!isset($_GET['pk'])) echo "You must specify a column."; else if(!isset($_GET['table']) || $_GET['table']=="") echo "You must specify a table name."; else { $query = "PRAGMA table_info('".$_GET['table']."')"; $result = $db->selectArray($query); for($i=0; $i"; echo ""; echo ""; echo ""; echo ""; //$headings = array("Field", "Type", "Primary Key", "Autoincrement", "Not NULL", "Default Value"); $headings = array("Field", "Type"); for($k=0; $k".$headings[$k].""; echo ""; $i = 0; $tdWithClass = ""; echo $tdWithClass; echo ""; echo ""; echo $tdWithClass; echo ""; echo ""; /* echo $tdWithClass; if($primarykeyVal) echo " Yes"; else echo " Yes"; echo ""; echo $tdWithClass; if(1==2) echo " Yes"; else echo " Yes"; echo ""; echo $tdWithClass; if($notnullVal) echo " Yes"; else echo " Yes"; echo ""; echo $tdWithClass; echo ""; echo ""; */ echo ""; echo ""; echo ""; echo ""; echo "
"; echo "
"; echo " "; echo "Cancel"; echo "
"; echo ""; } 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; /////////////////////////////////////////////// delete trigger case "trigger_delete": echo "
"; echo "
"; echo "Are you sure you want to delete trigger '".$_GET['pk']."'?

"; echo " "; echo "Cancel"; echo "
"; echo "
"; break; /////////////////////////////////////////////// create trigger case "trigger_create": echo "

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

"; if($_POST['tablename']=="") echo "You must specify a table name."; else { echo "
"; echo "Trigger name:

"; echo "
Database Event"; echo "Before/After: "; echo ""; echo "

"; echo "Event: "; echo ""; echo "


"; echo "
Trigger Action"; echo " For Each Row

"; echo "WHEN expression (type expression without 'WHEN'):
"; echo ""; echo "

"; echo "Trigger Steps (semicolon terminated):
"; echo ""; echo "


"; echo " "; echo "Cancel"; 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"; if($directory!==false && is_writable($directory)) { echo "Rename Database"; echo "Delete Database"; } 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 ".helpLink("SQLite Library Extensions").": ".$db->getType()."
"; echo "PHP version: ".phpversion()."

"; if(isset($_GET['sort'])) $_SESSION[COOKIENAME.'sort'] = $_GET['sort']; else unset($_SESSION[COOKIENAME.'sort']); if(isset($_GET['order'])) $_SESSION[COOKIENAME.'order'] = $_GET['order']; else unset($_SESSION[COOKIENAME.'order']); $query = "SELECT type, name FROM sqlite_master WHERE type='table' OR type='view'"; $queryAdd = ""; if(isset($_SESSION[COOKIENAME.'sort'])) $queryAdd .= " ORDER BY ".$_SESSION[COOKIENAME.'sort']; if(isset($_SESSION[COOKIENAME.'order'])) $queryAdd .= " ".$_SESSION[COOKIENAME.'order']; $query .= $queryAdd; $result = $db->selectArray($query); $j = 0; for($i=0; $i
"; else { echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; $totalRecords = 0; for($i=0; $inumRows($result[$i]['name']); $totalRecords += $records; $tdWithClass = ""; echo $tdWithClassLeft; echo "Table"; echo ""; 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 ""; } else { echo ""; echo $tdWithClassLeft; echo "View"; echo ""; 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 ""; echo ""; echo $tdWithClass; echo "Export"; echo ""; echo $tdWithClass; echo ""; echo ""; echo $tdWithClass; echo ""; echo ""; echo $tdWithClass; echo ""; echo ""; echo $tdWithClass; echo "Drop"; echo ""; echo $tdWithClass; echo $records; echo ""; echo ""; } } } echo ""; echo ""; echo ""; echo ""; echo "
"; echo "Type ".helpLink("Tables vs. Views"); if(isset($_SESSION[COOKIENAME.'sort']) && $_SESSION[COOKIENAME.'sort']=="type") echo (($_SESSION[COOKIENAME.'order']=="ASC") ? " " : " "); echo ""; echo "Name"; if(isset($_SESSION[COOKIENAME.'sort']) && $_SESSION[COOKIENAME.'sort']=="name") echo (($_SESSION[COOKIENAME.'order']=="ASC") ? " " : " "); echo "ActionRecords
"; $tdWithClassLeft = ""; if($result[$i]['type']=="table") { echo "
".sizeof($result)." total".$totalRecords."
"; echo "
"; } echo "
"; echo "Create new table on database '".$db->getName()."'"; echo "
"; echo "Name: "; echo "Number of Fields: "; echo ""; echo "
"; echo "
"; echo "
"; echo "
"; echo "Create new view on database '".$db->getName()."'"; echo "
"; echo "Name: "; echo "Select Statement ".helpLink("Writing a Select Statement for a New View").": "; 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_sql($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 ""; // 22 August 2011: gkf fixed bugs 46, 51 and 52. if($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 "
CSV"; echo "
"; echo "
Options"; echo " Export with structure ".helpLink("Export Structure to SQL File")."
"; echo " Export with data ".helpLink("Export Data to SQL File")."
"; echo " Add DROP TABLE ".helpLink("Add Drop Table to Exported SQL File")."
"; echo " Add TRANSACTION ".helpLink("Add Transaction to Exported SQL File")."
"; echo " Comments ".helpLink("Add Comments to Exported SQL File")."
"; echo "
"; echo ""; echo "
"; echo "

"; echo "
Save As"; echo ""; $file = pathinfo($db->getPath()); $name = $file['filename']; echo " "; echo "
"; echo "
"; } else if($view=="import") { if(isset($_POST['import'])) { echo "
"; if($importSuccess===true) echo "Import was successful."; else echo $importSuccess; echo "

"; } echo "
"; echo "
Import"; echo " SQL"; echo "
CSV"; echo "
"; echo "
Options"; echo "No options"; echo "
"; echo ""; echo "
"; echo "

"; echo "
File to import"; echo " "; echo "
"; } else if($view=="rename") { if(isset($dbexists)) { echo "
"; if($oldpath==$newpath) echo "Error: You didn't change the value dumbass."; else echo "Error: A database of the name '".$newpath."' already exists."; echo "

"; } if(isset($justrenamed)) { echo "
"; echo "Database '".$oldpath."' has been renamed to '".$newpath."'."; echo "

"; } echo ""; echo ""; echo "Rename database '".$db->getPath()."' to "; echo "
"; } else if($view=="delete") { echo "
"; echo "
"; echo "Are you sure you want to delete the database '".$db->getPath()."'?

"; echo ""; echo " "; echo "Cancel"; 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 ""; ?>