".I_SQL_ERROR."
"; // if sql_query was send to db if (($_POST['sql_query'] || $_FILES['sql_file']) && $_POST['db']) { // get start time to calculate duration if (function_exists("microtime")) { $microtime=explode(" ",microtime()); $starttime=($microtime[0]+$microtime[1]); } else { $starttime=time(); } // set php timelimit @set_time_limit($CONF['timelimit']); @ignore_user_abort(TRUE); // get the submited file if (is_uploaded_file($_FILES['sql_file']['tmp_name'])) { // run big_import.php if (isset($_POST['fragmented'])) { $filename=PMBP_EXPORT_DIR.$_FILES['sql_file']['name']; // rename to make it consistent @rename($_FILES['sql_file']['tmp_name'],$filename); if (file_exists($filename)) { echo ""; } // standard import } else { // trim lines and remove comments $sql_file=""; // remove comments and store sql queries in $sql_file while($line=PMBP_getln($_FILES['sql_file']['tmp_name'],false,$_FILES['sql_file']['name'])) { if (trim($line) && substr(trim($line),0,1)!="#" && substr(trim($line),0,2)!="--") $sql_file.=trim($line)."\n"; } PMBP_getln($_FILES['sql_file']['tmp_name'],true,$_FILES['sql_file']['name']); // do everything below once for the POST-data and once for the file $file_and_post=array($_POST['sql_query'],$sql_file); /* // alternative code instead of the paragraph before: // it uses exec_sql for executing the sql queries but does not output any query results!!! // extract zip file if (PMBP_file_info("comp",$_FILES['sql_file']['name'])=="zip") { include_once("pclzip.lib.php"); $pclzip = new PclZip($_FILES['sql_file']['tmp_name']); $extracted_file=$pclzip->extractByIndex(0,"./".PMBP_EXPORT_DIR,""); if ($pclzip->error_code!=0) $error="plczip: ".$pclzip->error_string."
".BI_BROKEN_ZIP."!"; $filename="./".PMBP_EXPORT_DIR.$extracted_file[0]["stored_filename"]; unset($pclzip); } $resultArray=PMBP_exec_sql($filehandler=gzopen($filename,"r"),$con); @gzclose($filehandler); @unlink($filename); print_r($resultArray); */ } } if(!isset($file_and_post)) { $file_and_post=array($_POST['sql_query']); } // for standard imports if (!isset($_POST['fragmented'])) { // $key > 0 when the source was a file foreach($file_and_post as $key=>$sql_queries) { // select the db if (!$key) mysql_select_db($_POST['db']); // replace these strings in the sql query. Do you know any more or a better way? if (!$key) { $str_find=array("\\'",'\\"',"\\\\"); //" $str_repl=array("'",'"',"\\"); //" $sql_queries=str_replace($str_find,$str_repl,$sql_queries); $sql_print=$sql_queries; } // separate sql queries and remove empty queries $all_queries=str_replace(";\n",";|:-:--:-:|",$sql_queries); $all_queries=str_replace(";\r\n",";|:-:--:-:|",$all_queries); $queries=explode("|:-:--:-:|",$all_queries); // to remove empty rows $all_queries=""; foreach($queries as $number=>$query) if (strlen($query)>1) $all_queries[$number]=$query; // execute sql queries $i=0; $sql_error=FALSE; if (is_array($all_queries)) { foreach($all_queries as $query) { $i++; if (!$key) echo "
".SQ_RESULT." ".$i.":
\n"; // error if: no result AND error is not 'empty result' OR: error is empty result and its the first error if ((!$res=mysql_query($query) AND mysql_errno()!=1065) OR (mysql_errno()==1065 AND !$sql_error)){ echo $query."\n
".mysql_error()."

\n"; if ($key) $sql_error.="F".$i.", "; else $sql_error.=$i.", "; } elseif (mysql_errno()!=1065) { // print result table if (!$key) { echo "\n"; // print field names echo "\n"; for($j=0,$field_names="";$field_names[]=@mysql_field_name($res,$j);$j++) echo ""; echo "\n"; // print query results $result_exists=FALSE; while($result=@mysql_fetch_array($res,MYSQL_NUM)) { $result_exists=TRUE; if (!$key) echo ""; foreach($result as $field) if ($field!="" && !$key) echo ""; else echo ""; if (!$key) echo "\n"; } // print number of rows or if empty mysql result print number of affected rows if (!$result_exists) { if (!$key) echo "\n\n\n"; if (!$affected=@mysql_affected_rows()) $affected=0; } else { if (!$affected=@mysql_num_rows($res)) $affected=0; } echo "\n\n\n"; echo "
".$field_names[$j]."
".htmlentities($field)." 
".SQ_SUCCESS."
".SQ_AFFECTED.": ".$affected."

\n"; } } } } if (!$key && isset($_FILES['sql_file']['filename'])) echo "======== ".$_FILES['sql_file']['name']." ========
\n"; } } // print errors and final message if the import was not fragmented if (!isset($_POST['fragmented'])) { // print errors or message of success if ($sql_error) echo "
".SQ_ERROR." ".$sql_error."
\n"; else echo "
".SQ_SUCCESS."
\n"; // print execution duration if (function_exists("microtime")) { $microtime=explode(" ",microtime()); $endtime=($microtime[0]+$microtime[1]); } else { $endtime=time(); } echo "
".F_DURATION.": ".number_format($endtime-$starttime,3)." ".F_SECONDS."


\n"; } } // print html form and show last selected database and last queries echo "
\n
\n"; echo "
".SQ_WARNING."
\n"; // print database select echo SQ_SELECT_DB.":
\n
"; // print sql textarea and submit button echo "
".SQ_INSERT.":
\n"; echo ""; echo "

".SQ_FILE.":
\n".$_POST['sql_file']; echo "

\n\n"; echo "\n    ( ".B_IMPORT_FRAG.")
\n"; echo "
\n
\n"; PMBP_print_footer(); ?>