0) { $SQL_ARRAY=file($sf); } } function WriteSQL() { global $SQL_ARRAY,$config; $sf=$config["paths"]["config"].'sql_statements'; $str=""; for($i=0;$i'.$nl; $s.=''.$nl; if(count($SQL_ARRAY)>0) { for($i=0;$i'.SQL_Name($i).''.$nl; } } $s.=''.$nl.$nl; return $s; } function Table_ComboBox() { global $db,$config,$lang,$nl; $tabellen = mysql_list_tables($db,$config["dbconnection"]); $num_tables = mysql_num_rows($tabellen); $s=$nl.$nl.''.$nl.$nl; return $s; } function DB_Exists($db) { global $config; if(!isset($config["dbconnection"])) MSD_mysql_connect(); $erg=false; $dbs=mysql_list_dbs($config["dbconnection"]); while ($row = mysql_fetch_object($dbs)) { if(strtolower($row->Database)==strtolower($db)) { $erg=true;break; } } return $erg; } function Table_Exists($db,$table) { global $config; if(!isset($config["dbconnection"])) MSD_mysql_connect(); $erg=false; $sqlt="SHOW TABLES FROM `$db`"; $res=MSD_query($sqlt) or die(SQLError($sqlt,mysql_error())); if($res) { $row = mysql_fetch_row($res); if(strtolower($row[0])==strtolower($table)) { $erg=true; } } else die("ERROR"); return $erg; } function DB_Empty($dbn) { $r="DROP DATABASE `$dbn`;\nCREATE DATABASE `$dbn`;"; MSD_DoSQL($r); } function DB_Copy($source,$destination,$drop_source=0,$insert_data=1) { global $config; if(!isset($config["dbconnection"])) MSD_mysql_connect(); $SQL_Array=$t=""; if(!DB_Exists($destination)) $SQL_Array.="CREATE DATABASE `$destination` ;\n"; $SQL_Array.="USE `$destination` ;\n"; $tabellen = mysql_list_tables($source,$config["dbconnection"]); $num_tables = mysql_num_rows($tabellen); for($i=0;$i<$num_tables;$i++) { $table=mysql_tablename($tabellen,$i); $sqlt="SHOW CREATE TABLE `$source`.`$table`"; $res=MSD_query($sqlt) or die(SQLError($sqlt,mysql_error())); $row=mysql_fetch_row($res); $c=$row[1]; if(substr($c,-1)==";") $c=substr($c,0,strlen($c)-1); $SQL_Array.=($insert_data==1) ? "$c SELECT * FROM `$source`.`$table` ;\n" : "$c ;\n"; } if($drop_source==1) $SQL_Array.="DROP DATABASE `$source` ;"; mysql_select_db($destination); MSD_DoSQL($SQL_Array); } function Table_Copy($source,$destination,$insert_data,$destinationdb="") { global $config; if(!isset($config["dbconnection"])) MSD_mysql_connect(); $SQL_Array=$t=""; $sqlc="SHOW CREATE TABLE $source"; $res=MSD_query($sqlc) or die(SQLError($sqlc,mysql_error())); $row=mysql_fetch_row($res); $c=$row[1]; $a1=strpos($c,"`"); $a2=strpos($c,"`",$a1+1); $c=substr($c,0,$a1+1).$destination.substr($c,$a2); if(substr($c,-1)==";") $c=substr($c,0,strlen($c)-1); $SQL_Array.=($insert_data==1) ? "$c SELECT * FROM $source ;\n" : "$c ;\n"; //echo "
$SQL_Array
"; MSD_DoSQL($SQL_Array); } function MSD_DoSQL($sqlcommands,$limit="") { global $config,$out,$numrowsabs,$numrows,$num_befehle,$time_used,$sql; if(!isset($sql["parser"]["sql_commands"])) $sql["parser"]["sql_commands"]=0; if(!isset($sql["parser"]["sql_errors"])) $sql["parser"]["sql_errors"]=0; $sql["parser"]["time_used"]=getmicrotime(); if(!isset($config["dbconnection"])) MSD_mysql_connect(); $out=$sqlcommand=""; $allSQL=explode("\n",$sqlcommands); $sql_queries=count($allSQL); if(!isset($allSQL[$sql_queries-1])) $sql_queries--; if($sql_queries==1) { SQLParser($allSQL[0]); $sql["parser"]["sql_commands"]++; $out.=Stringformat(($sql["parser"]["sql_commands"]),4).": ". $allSQL[0]."\n"; $result =MSD_query($allSQL[0]) or die(SQLError($allSQL[0],mysql_error())); } else { for($i=0;$i<$sql_queries; $i++) { $allSQL[$i]=trim(rtrim($allSQL[$i])); if($allSQL[$i]!="") { $sqlcommand.=$allSQL[$i]; SQLParser($sqlcommand); if($sql["parser"]["start"]==0 && $sql["parser"]["end"]==0) { //sql complete $sql["parser"]["sql_commands"]++; $out.=Stringformat(($sql["parser"]["sql_commands"]),4).": ". $sqlcommand."\n"; $result =MSD_query($sqlcommand) or die(SQLError($sqlcommand,mysql_error())); $sqlcommand=""; } } } } $sql["parser"]["time_used"]=getmicrotime()-$sql["parser"]["time_used"]; } function SQLParser($s,$debug=0) { global $sql; $sql["parser"]["start"]=$sql["parser"]["end"]=0; $sql["parser"]["sqlparts"]=0; if(!isset($sql["parser"]["drop"])) $sql["parser"]["drop"]=0; if(!isset($sql["parser"]["create"])) $sql["parser"]["create"]=0; if(!isset($sql["parser"]["insert"])) $sql["parser"]["insert"]=0; if(!isset($sql["parser"]["update"])) $sql["parser"]["update"]=0; if(!isset($sql["parser"]["comment"])) $sql["parser"]["comment"]=0; $Backslash=chr(92); $s=rtrim(trim(strtoupper(($s)))); //Was ist das für eine Anfrage ? if(substr($s,0,1)=="#" || substr($s,0,2)=="--") { $sql["parser"]["comment"]++; } elseif(substr($s,0,5)=="DROP ") { $sql["parser"]["drop"]++; } elseif(substr($s,0,7)=="CREATE ") { //Hier nur die Anzahl der Klammern zählen $sql["parser"]["start"]=1; $kl1=substr_count($s,"("); $kl2=substr_count($s,")"); if($kl2-$kl1==0) { $sql["parser"]["start"]=0; $sql["parser"]["create"]++; } } elseif(substr($s,0,7)=="INSERT " || substr($s,0,7)=="UPDATE ") { if(substr($s,0,7)=="INSERT ") $sql["parser"]["insert"]++; else $sql["parser"]["update"]++; $i=strpos($s," VALUES")+7; $s=substr($s,$i); $i=strpos($s,"(")+1; $s=substr($s,$i); $s=substr($s,0,strlen($s)-2); $tb=explode(",",$s); for ($i=0;$i2) { $sql["parser"]["end"]=1; } elseif (($B_Delimiter % 2)==1 && strlen($v)>2) { //ist mit `'` maskiert $sql["parser"]["end"]=0; } elseif(($B_Esc % 2)==1) { //ist mit Backslash maskiert $sql["parser"]["end"]=0; } else { $sql["parser"]["end"]=1; } } } if($debug==1) echo "".$sql["parser"]["start"]."/".$sql["parser"]["end"]." Feld $i: ".htmlspecialchars($tb[$i])."- ".$sql["parser"]["sqlparts"]." ($B_Ticks / $B_Esc)
"; if($sql["parser"]["start"]==1 && $sql["parser"]["end"]==1) { $sql["parser"]["sqlparts"]++; $sql["parser"]["start"]=$sql["parser"]["end"]=0; } } } } function SQLOutput($sqlcommand,$meldung="") { global $sql,$lang; $s= '
'; if($meldung!="") $s.='

'.$meldung.'

'; $s.='
'.$lang['sql_output'].'
'; $s.=''.$sql["parser"]["sql_commands"].''.$lang['sql_commands_in'].round($sql["parser"]["time_used"],4).$lang['sql_commands_in2'].'

'; $s.=$lang['sql_out1'].''.$sql["parser"]["drop"].' DROP-, '; $s.=''.$sql["parser"]["create"].' CREATE-, '; $s.=''.$sql["parser"]["insert"].' INSERT-, '; $s.=''.$sql["parser"]["update"].' UPDATE-'.$lang['sql_out2'].'
'; $s.=$lang['sql_out3'].''.$sql["parser"]["comment"].' '.$lang['sql_out4'].'
'; if($sql["parser"]["sql_commands"]<5000) $s.='
'.highlight_sql($sqlcommand).'
'; else $s.=$lang['sql_out5'].""; return $s; } function GetCreateTable($db,$tabelle) { global $config; if(!isset($config["dbconnection"])) MSD_mysql_connect(); $res=mysql_query("SHOW CREATE TABLE `$db`.`$tabelle`"); if($res) { $row=mysql_fetch_array($res); return $row["Create Table"]; } else return mysql_error(); } function KindSQL($sql) { if (preg_match('@^((-- |#)[^\n]*\n|/\*.*?\*/)*(DROP|CREATE)[[:space:]]+(IF EXISTS[[:space:]]+)?(TABLE|DATABASE)[[:space:]]+(.+)@im', $sql)) { return 2; } elseif (preg_match('@^((-- |#)[^\n]*\n|/\*.*?\*/)*(DROP|CREATE)[[:space:]]+(IF EXISTS[[:space:]]+)?(TABLE|DATABASE)[[:space:]]+(.+)@im', $sql)) { return 1; } } function GetPostParams() { global $db,$dbid,$tablename,$context,$limitstart,$order,$orderdir,$sql; $db=$_POST["db"]; $dbid=$_POST["dbid"]; $tablename=$_POST["tablename"]; $context=$_POST["context"]; $limitstart=$_POST["limitstart"]; $order=$_POST["order"]; $orderdir=$_POST["orderdir"]; $sql["sql_statement"]=(isset($_POST["sql"])) ? stripslashes(urldecode($_POST["sql"])) : "SELECT * FROM `$tablename`"; } function ComboCommandDump($when,$index) { global $SQL_ARRAY,$nl,$databases; if($when==0) { $r=''; $csql=$databases["command_after_dump"][$index]; } $r.=''; if(count($SQL_ARRAY)>0) { for($i=0;$i'.SQL_Name($i).''.$nl; } } $r.=''; return $r; } function EngineCombo($default="") { global $config; if(!$config["dbconnection"]) MSD_mysql_connect(); $r=''; if(!MSD_NEW_VERSION) { //BDB | HEAP | ISAM | InnoDB | MERGE | MRG_MYISAM | MYISAM $r.=''; $r.=''; $r.=''; $r.=''; $r.=''; $r.=''; $r.=''; } else { $res=mysql_query("SHOW ENGINES"); $num = mysql_num_rows($res); for($i=0;$i<$num;$i++) { $row=mysql_fetch_array($res); $r.=''; } } return $r; } function CharsetCombo($default="") { global $config; if(!MSD_NEW_VERSION) { return ""; } else { if(!isset($config["dbconnection"])) MSD_mysql_connect(); $res=mysql_query("SHOW Charset"); $num = mysql_num_rows($res); $r=''; for($i=0;$i<$num;$i++) { $row=mysql_fetch_array($res); $r.=''; } return $r; } } function GetCollationArray() { global $config; if(!isset($config["dbconnection"])) MSD_mysql_connect(); $res=mysql_query("SHOW Collation"); $num = mysql_num_rows($res); $r=Array(); for($i=0;$i<$num;$i++) { $row=mysql_fetch_array($res); $r[$i]["Collation"]=$row["Collation"]; $r[$i]["Charset"]=$row["Charset"]; $r[$i]["Id"]=$row["Id"]; $r[$i]["Default"]=$row["Default"]; $r[$i]["Compiled"]=$row["Compiled"]; $r[$i]["Sortlen"]=$row["Sortlen"]; } return $r; } function CollationCombo($default="") { if(!MSD_NEW_VERSION) { return ""; } else { $r=GetCollationArray(); sort($r); $s=""; $s=''; $group=""; for($i=0;$i'; } $s.=''; } return $s; } } function simple_bbcode_conversion($a) { global $config; $tag_start='
'; $tag_end='
'; //replacements $a=nl2br($a); $a=preg_replace("/\[url=(.*?)\](.*?)\[\/url\]/si","$2",$a); $a=preg_replace("/\[urltargetself=(.*?)\](.*?)\[\/urltargetself\]/si","$2",$a); $a=preg_replace("/\[url\](.*?)\[\/url\]/si","$1",$a); $a=preg_replace("/\[ed2k=\+(.*?)\](.*?)\[\/ed2k\]/si","$2",$a); $a=preg_replace("/\[ed2k=(.*?)\](.*?)\[\/ed2k\]/si","$2",$a); $a=preg_replace("/\[center\](.*?)\[\/center\]/si", "
$1
", $a); $a=preg_replace("/\[size=([1-2]?[0-9])\](.*?)\[\/size\]/si", "$2", $a); $a=preg_replace("/\[size=([1-2]?[0-9]):(.*?)\](.*?)\[\/size(.*?)\]/si", "$3", $a); $a=preg_replace("/\[font=(.*?)\](.*?)\[\/font\]/si", "$2", $a); $a=preg_replace("/\[color=(.*?)\](.*?)\[\/color\]/si", "$2", $a); $a=preg_replace("/\[color=(.*?):(.*?)\](.*?)\[\/color(.*?)\]/si", "$3", $a); $a=preg_replace("/\[img\](.*?)\[\/img\]/si", "", $a); $a=preg_replace("/\[b\](.*?)\[\/b\]/si", "$1", $a); $a=preg_replace("/\[b(.*?)\](.*?)\[\/b(.*?)\]/si", "$2", $a); $a=preg_replace("/\[u\](.*?)\[\/u\]/si", "$1", $a); $a=preg_replace("/\[u(.*?)\](.*?)\[\/u(.*?)\]/si", "$2", $a); $a=preg_replace("/\[i\](.*?)\[\/i\]/si", "$1", $a); $a=preg_replace("/\[i(.*?)\](.*?)\[\/i(.*?)\]/si", "$2", $a); $a=preg_replace("/\[quote\](.*?)\[\/quote\]/si", "

$1

", $a); $a=preg_replace("/\[quote:(.*?)\](.*?)\[\/quote(.*?)\]/si", "

$2

", $a); $a=preg_replace("/\[code:(.*?)\](.*?)\[\/code(.*?)\]/si", "

$2

", $a); $a=preg_replace("/\[hide\](.*?)\[\/hide\]/si", "
$1
", $a); $a=preg_replace("/[[:space:]]http:\/\/(.*?)[[:space:]]/si","$1",$a); return $tag_start.$a.$tag_end; } function ExtractTablename($q) { $offset=0; $p=strtoupper($q); $i=strpos($p,"FROM")+5; $p=substr($p,$i); if(substr($p,0,1)=="("){ $offset=2; echo "$offset
"; } if(strpos($p," ",$offset)) { $j=strpos($p," ",$offset); $p=substr($p,$offset,$j); } $t=substr($q,$i+$offset,strlen($p)-$offset); if(substr($t,-1)==",") { //Achtung, keine eindeutige Tabelle $t=''; } if(substr($t,0,1)=="`" && substr($t,-1)=="`") $t=substr($t,1,strlen($t)-2); return $t; } function GetOptionsCombo($arr,$default) { global $feldtypen,$feldattribute,$feldnull,$feldextras,$feldkeys,$feldrowformat; $r=""; foreach ($arr as $s) { $r.=''."\n"; } return $r; } function DefaultFieldVals() { $dfv=Array(); $dfv["VARCHAR"]["defaultsize"]=255; $dfv["VARCHAR"]["maxsize"]=255; $dfv["TINYINT"]["defaultsize"]=255; $dfv["TINYINT"]["maxsize"]=255; $dfv["TEXT"]["defaultsize"]=""; $dfv["TEXT"]["maxsize"]=65535; $dfv["DATE"]["defaultsize"]=255; $dfv["DATE"]["maxsize"]=255; $dfv["SMALLINT"]["defaultsize"]=255; $dfv["SMALLINT"]["maxsize"]=255; $dfv["MEDIUMINT"]["defaultsize"]=255; $dfv["MEDIUMINT"]["maxsize"]=255; $dfv["INT"]["defaultsize"]=11; $dfv["INT"]["maxsize"]=16; $dfv["BIGINT"]["defaultsize"]=255; $dfv["BIGINT"]["maxsize"]=255; $dfv["FLOAT"]["defaultsize"]=255; $dfv["FLOAT"]["maxsize"]=255; $dfv["DOUBLE"]["defaultsize"]=255; $dfv["DOUBLE"]["maxsize"]=255; $dfv["DECIMAL"]["defaultsize"]=255; $dfv["DECIMAL"]["maxsize"]=255; $dfv["DATETIME"]["defaultsize"]=255; $dfv["DATETIME"]["maxsize"]=255; $dfv["TIMESTAMP"]["defaultsize"]=255; $dfv["TIMESTAMP"]["maxsize"]=255; $dfv["TIME"]["defaultsize"]=255; $dfv["TIME"]["maxsize"]=255; $dfv["YEAR"]["defaultsize"]=255; $dfv["YEAR"]["maxsize"]=255; $dfv["CHAR"]["defaultsize"]=255; $dfv["CHAR"]["maxsize"]=255; $dfv["TINYBLOB"]["defaultsize"]=255; $dfv["TINYBLOB"]["maxsize"]=255; $dfv["TINYTEXT"]["defaultsize"]=255; $dfv["TINYTEXT"]["maxsize"]=255; $dfv["BLOB"]["defaultsize"]=255; $dfv["BLOB"]["maxsize"]=255; $dfv["MEDIUMBLOB"]["defaultsize"]=255; $dfv["MEDIUMBLOB"]["maxsize"]=255; $dfv["MEDIUMTEXT"]["defaultsize"]=255; $dfv["MEDIUMTEXT"]["maxsize"]=255; $dfv["LONGBLOB"]["defaultsize"]=255; $dfv["LONGBLOB"]["maxsize"]=255; $dfv["LONGTEXT"]["defaultsize"]=255; $dfv["LONGTEXT"]["maxsize"]=255; $dfv["ENUM"]["defaultsize"]=255; $dfv["ENUM"]["maxsize"]=255; $dfv["SET"]["defaultsize"]=255; $dfv["SET"]["maxsize"]=255; return $dfv; } function FillFieldinfos($db,$tabelle) { global $config; $t=GetCreateTable($db,$tabelle); $fields_infos=Array(); $fields_infos["_primarykey_"]=""; $flds=$keys=$ukeys=$fkeys=0; $fields_infos["_createtable_"]=$t; $tmp=explode("\n",$t); for($i=1;$i"; if(substr($t,0,12)=="PRIMARY KEY ") { $t=str_replace("`","",$t); $fields_infos["_primarykey_"]=substr($t,strpos($t,"(")+1,strpos($t,")")-strpos($t,"(")-1); } elseif (substr($t,0,4)=="KEY ") { $t=str_replace("`","",$t); $att=explode(" ",$t); $fields_infos["_key_"][$keys]["name"]=$att[1]; $att[2]=str_replace("(","",$att[2]); $att[2]=str_replace(")","",$att[2]); $fields_infos["_key_"][$keys]["columns"]=$att[2]; $keys++; } elseif (substr($t,0,11)=="UNIQUE KEY ") { $t=str_replace("`","",$t); $att=explode(" ",$t); $fields_infos["_uniquekey_"][$ukeys]["name"]=$att[2]; $att[3]=str_replace("(","",$att[3]); $att[3]=str_replace(")","",$att[3]); $fields_infos["_uniquekey_"][$ukeys]["columns"]=$att[3]; $ukeys++; } elseif (substr($t,0,13)=="FULLTEXT KEY ") { $t=str_replace("`","",$t); $att=explode(" ",$t); $fields_infos["_fulltextkey_"][$fkeys]["name"]=$att[2]; $att[3]=str_replace("(","",$att[3]); $att[3]=str_replace(")","",$att[3]); $fields_infos["_fulltextkey_"][$fkeys]["columns"]=$att[3]; $fkeys++; } else { $att=explode(" ",$t); if(substr($att[0],0,1)=="`" && substr($att[0],-1)=="`") { $fields_infos[$flds]["name"]=str_replace("`","",$att[0]); $s=1; } else { $fields_infos[$flds]["name"]=str_replace("`","",$att[0])." "; for($ii=1;$i"; $s++; } } $flds++; } } //echo substr($tmp[count($tmp)-1],2)."
"; $ext=explode(" ",substr($tmp[count($tmp)-1],2)); $s="";$haltchar="="; for($i=0;$i"; if($ok[0]==0 && $nk[0]==1) { $s.="ADD PRIMARY KEY (`$fld`), "; } elseif ($ok[0]==1 && $nk[0]==0) { $s.="DROP PRIMARY KEY, "; } if($ok[1]==0 && $nk[1]==1) { $s.="ADD UNIQUE INDEX `$fld` (`$fld`), "; } elseif ($ok[1]==1 && $nk[1]==0) { $s.="DROP INDEX `$fld`, "; } if($ok[2]==0 && $nk[2]==1) { $s.="ADD INDEX `$fld` (`$fld`), "; } elseif ($ok[2]==1 && $nk[2]==0) { $s.="DROP INDEX `$fld`, "; } if($ok[3]==0 && $nk[3]==1) { $s.="ADD FULLTEXT INDEX `$fld` (`$fld`($size)), "; } elseif ($ok[3]==1 && $nk[3]==0) { $s.="DROP FULLTEXT INDEX `$fld`, "; } } if($s!="") $s=substr($s,0,strlen($s)-2); return $s; } ?>