Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
salve salve galera... to com um grande problema aqui.. curte só... to tentando executa um script de backup só que esta dando problema com os acentos... e eu ja to ficando loko com isso hehehehe... alguem ai conseguiria me ajudar?!
segue corigo!
<?php header("Content-Type: text/html; charset=UTF-8",true); ?><html> <body> Iniciando backup, aguarde...<br /> <?php //config define("SERVIDOR", "****"); define("USUARIO", "****"); define("SENHA", "****"); //end config //init.php/* error_reporting("E_ALL"); @ini_set('memory_limit', '300'); @ini_set('display_errors', '1'); @ini_set('register_globals', '1'); set_time_limit(0);*/ if(!extension_loaded('mysql')): echo( "Nao esta habilitada a dll Mysql" ); exit; endif; //end init.php if(mysql_connect(SERVIDOR, USUARIO, SENHA)): $re = mysql_query("SHOW DATABASES"); else: echo "Nao foi possivel conectar no banco de dados"; exit; endif; function setBackup($tableName, $dbName){ $tabela = $tableName; $sql = ""; //$sql = "-- Sistema de backup Agência Web 2007\r\n"; //$sql .= "-- Servidor: ". SERVIDOR ."\r\n"; //$sql .= "-- Banco de dados: ". $dbName ."\r\n"; //$sql .= "-- Data backup: ". date("d/m/Y H:i:s")."\r\n"; //$sql .= "-- Versao MySQL: ". mysql_get_server_info()."\r\n"; //$sql .= "-- Versao PHP: ". phpversion()."\r\n\r\n"; $sql .= "-- MySQL Administrator dump 1.4\r\n"; $sql .= "--\r\n"; $sql .= "-- ------------------------------------------------------\r\n"; $sql .= "-- Server version 4.1.21-community-nt\r\n\r\n\r\n"; $sql .= "/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;\r\n"; $sql .= "/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;\r\n"; $sql .= "/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;\r\n"; $sql .= "/*!40101 SET NAMES utf8 */;\r\n\r\n"; $sql .= "/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;\r\n"; $sql .= "/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;\r\n"; $sql .= "/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;\r\n\r\n\r\n"; $sql .= "--\r\n"; $sql .= "-- Create schema ".$dbName."\r\n"; $sql .= "--\r\n\r\n"; $sql .= "CREATE DATABASE IF NOT EXISTS ".$dbName.";\r\n"; $sql .= "USE ".$dbName.";\r\n\r\n"; mysql_select_db($dbName) or die ( mysql_error()."<br>".$dbName ); $re = mysql_query("SHOW TABLE STATUS") or die ( mysql_error()."<br>SHOW TABLE STATUS" ); while($l = mysql_fetch_assoc($re)): $tbl_stat[$l["Name"]] = $l["Auto_increment"]; endwhile; for($i = 0; $i < count($tabela); $i++): $re2 = mysql_query("SHOW CREATE TABLE ".$tabela[$i]) or die ( mysql_error()."<br>SHOW CREATE TABLE ".$tabela[$i] ); $sql .= "--\r\n"; $sql .= "-- Definition of table `".$tabela[$i]."`\r\n"; $sql .= "--\r\n\r\n"; $sql .= "DROP TABLE IF EXISTS `".$tabela[$i]."`; \r\n"; $l2 = mysql_fetch_array($re2) or die ( mysql_error() ); if($tbl_stat[$tabela[$i]] != ""): //$sql .= str_replace(" ", "\t", str_replace("`", "", $l2[1])). " AUTO_INCREMENT=". $tbl_stat[$tabela[$i]] .";\r\n\r\n"; $sql .= str_replace(" ", "\t", str_replace("|>|>", "", $l2[1])). " AUTO_INCREMENT=". $tbl_stat[$tabela[$i]] .";\r\n\r\n"; else: //$sql .= str_replace(" ", "\t", str_replace("`", "", $l2[1])).";\r\n\r\n"; $sql .= str_replace(" ", "\t", str_replace("|>|>", "", $l2[1])).";\r\n\r\n"; endif; $re3 = mysql_query("SHOW COLUMNS FROM ".$tabela[$i]) or die ( mysql_error()."<br>SHOW COLUMNS FROM ".$tabela[$i]); $campos = ""; while($row = mysql_fetch_array($re3)): $campos[] = "`".$row[0]."`"; endwhile; $re4 = mysql_query("SELECT * FROM ".$tabela[$i]) or die ( mysql_error()."<br>SHOW COLUMNS FROM ".$tabela[$i]); if(mysql_num_rows($re4)): $sql .= "--\r\n"; $sql .= "-- Dumping data for table `".$tabela[$i]."`\r\n"; $sql .= "--\r\n\r\n"; $sql .= "/*!40000 ALTER TABLE `acessos` DISABLE KEYS */;\r\n"; while($dt = mysql_fetch_row($re4)): $valores = ""; for($j = 0; $j < sizeof($dt); $j++): //$valores[] .= "'". $dt[$j] ."'"; $valores[] .= "'".setTratamento($dt[$j])."'"; endfor; $campo = implode(", ", $campos); $valor = implode(", ", $valores); $sql .= "INSERT INTO ".$tabela[$i]." (".$campo.") VALUES (".$valor.");\r\n"; endwhile; $sql .= "/*!40000 ALTER TABLE `acessos` ENABLE KEYS */;\r\n"; endif; $sql .= "\r\n\r\n\r\n\r\n"; endfor; $sql .= "/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;\r\n"; $sql .= "/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;\r\n"; $sql .= "/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;\r\n"; $sql .= "/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;\r\n"; $sql .= "/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;\r\n"; $sql .= "/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;\r\n"; $sql .= "/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;\r\n"; $pasta = date('Ymd'); if(file_exists($pasta)): if(!is_writable($pasta)): chmod($pasta,0777); endif; else: mkdir($pasta.'/'); endif; //$sql .= "-- FIM DO BACKUP;\r\n"; $nome = $pasta.'/'.$dbName; $fp = fopen($nome.".sql", "w+"); if(!fwrite($fp, $sql)): echo "Erro na criação do arquivo, verifique a permissao de escrita"; exit; endif; fclose($fp); if(file_exists($nome.'.sql')): return "<span style='color:#FF0000'> Status: OK</span>"; //echo "Arquivo criado com sucesso. Arquivo localizado em: ".$nome.'.sql<br>'; else: return "<span style='color:#000000'> Status: ERRO</span>"; //echo "Arquivo não criado!"; endif; //exit; } function setTratamento($coluna){ /*$a = array( "'"=>"\'", "'"=>"\'", "\\"=> '\\\\'); // Tira o acento pela chave do array $nomes = preg_replace(array_keys($a), array_values($a), $coluna); //$nome_final = strtolower($nomes); return $nomes; */ $aux = str_replace("\\","\\\\",$coluna); $aux = str_replace("'","\'",$coluna); return $aux; } function teste($tableName, $dbName){ mysql_select_db($dbName) or die ( mysql_error()."<br>".$dbName ); $re = mysql_query("SHOW TABLE STATUS") or die ( mysql_error()."<br>SHOW TABLE STATUS" ); while($l = mysql_fetch_assoc($re)): $tbl_stat[$l["Name"]] = $l["Auto_increment"]; endwhile; return $tbl_stat; } $arrayNaoUsar = array("information_schema", "mysql", "apomedil", "agrihaus", "agenciaweb_novo", "afubrarh", "afubra", "aci_teste", "aci" ); while($l = mysql_fetch_array($re)): //if($l[0] != "information_schema" && $l[0] != "mysql" && $l[0] != "test"): //if(!in_array($l[0],$arrayNaoUsar)): if($l[0] == "agenciaweb"): echo "<b>Banco ".$l[0].": </b>"; $res = mysql_list_tables($l[0]) or die ( mysql_error()); $tabelas = array(); while($row = mysql_fetch_row($res)): $tabelas[] = $row[0]; endwhile; echo setBackup($tabelas, $l[0]); echo "<br>"; flush(); endif; endwhile; ?> </body></html>Carregando comentários...