function autoBakTablesBags() { set_time_limit(0); $tables=$this->getTables(); $tables = array_col_values($tables,'name'); $bagsize=1; $file=date('Y-m-d-H-i-').substr(base64_encode(md5(time().rand(0,10000000000000))),0,6); $_path=ROOT."/data/$file/sql-".$file; tool::mkdir(dirname($_path.'.ext')); $tabledump=''; if (is_array($tables)) foreach ($tables as $table) { $tabledump .= "DROP TABLE IF EXISTS $table;\n"; $create=mysql_fetch_row($this->query("SHOW CREATE TABLE `$table` ")); $create_str=$create[1]; if (front::post('mysql4')) $create_str=preg_replace('/ENGINE=.+?$/','',$create_str); $tabledump .= $create_str.";\n"; } $bag=1; if (is_array($tables)) foreach ($tables as $table) { $rows=$this->query("SELECT * FROM $table "); $numfields=mysql_num_fields($rows); $numrows=mysql_num_rows($rows); while ($row=mysql_fetch_row($rows)) { $comma=""; $tabledump .= "INSERT INTO $table VALUES("; for ($i=0;$i <$numfields;$i++) { $tabledump .= $comma."'".mysql_escape_string($row[$i])."'"; $comma=","; } $tabledump .= ");\n"; if (strlen($tabledump) >$bagsize * 1024 * 1024) { file_put_contents($_path.'-'.$bag.'.sql',$tabledump); $bag++; $tabledump=''; } } $tabledump .= "\n"; } if ($tabledump) file_put_contents($_path.'-'.$bag.'.sql',$tabledump); }
function array_col_values_unique($arr, $col) { return array_unique(array_col_values($arr, $col)); }