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替换。
答案 0 :(得分:1)
您需要将ereg_replace
替换为preg_replace
,请参阅以下示例:
print $input."<hr>".ereg_replace('/&/', ':::', $input);
成为
print $input."<hr>".preg_replace('/&/', ':::', $input);