2017-06-08 5 views
-1
function backup_tables($host,$user,$pass,$name,$tables = 'collection_detail, coupon_detail, coupon_redeem_log, coupon_shopping_cart, customer_address, customer_detail, dairy_sales_detail, delivery_types, item_detail, locked_date, user_login_detail') 
{ 


$link = mysqli_connect($host,$user,$pass,$name); 

//get all of the tables 
if($tables == '*') 
{ 
    $tables = array(); 
    $result = mysqli_query($link, 'SHOW TABLES'); 
    while($row = mysqli_fetch_row($result)) 
    { 
     $tables[] = $row[0]; 
    } 
} 
else 
{ 
    $tables = is_array($tables) ? $tables : explode(',',$tables); 
} 

//cycle through 
foreach($tables as $table) 
{ 
    $result = mysqli_query($link, 'SELECT * FROM '.$table); 
    $num_fields = mysqli_num_fields($result); 
    $return =""; 
    $return.= 'DROP TABLE IF EXISTS '.$table.';'; 
    $row2 = mysqli_fetch_row(mysqli_query($link,'SHOW CREATE TABLE '.$table)); 
    $return.= "\n\n".$row2[1].";\n\n"; 

    for ($i = 0; $i < $num_fields; $i++) 
    { 
     while($row = mysqli_fetch_row($result)) 
     { 
      $return.= 'INSERT INTO '.$table.' VALUES('; 
      for($j=0; $j < $num_fields; $j++) 
      { 
       $row[$j] = addslashes($row[$j]); 
       $row[$j] = ereg_replace("\n","\\n",$row[$j]); 
       if (isset($row[$j])) { $return.= '"'.$row[$j].'"' ; } else { $return.= '""'; } 
       if ($j < ($num_fields-1)) { $return.= ','; } 
      } 
      $return.= ");\n"; 
     } 
    } 
    $return.="\n\n\n"; 
}} 

誰かがeregの正しい置き換えを教えてくれますか?廃止されました:関数ereg_replace()は、44行目のC: Wamp www boot backup.phpで非推奨です。

+0

にpreg_replaceが参考にする必要がありますになります。 http://php.net/manual/en/function.preg-replace.php –

+0

私はそれをpreg_replaceと置き換えると、空の正規表現のエラーが表示されます。あなたは私に正しい構文を教えてくれますか? –

+0

正規表現の構文を読んでいるはずです。おそらく、現在の文字列と必要な新しい文字列について説明すると、私はあなたのためにpreg_replaceを書き換えることができます。 –

答えて

1

あなたは、以下の例を参照してください、preg_replaceereg_replaceを交換する必要があります。

print $input."<hr>".ereg_replace('/&/', ':::', $input); 

print $input."<hr>".preg_replace('/&/', ':::', $input); 
関連する問題