Hi all,
In one of my scripts I have a backup section. I upgraded to php 5, and now the backup script times out. I have narrowed it down to the mysql_real_escape_string function. If I leave that line out, and instead spit out the raw data, the script is done in a flash. Can anybody advice how to solve this (Or.. if you have a better way of doing this -without shell scripts-..)? The function I use is as follows:
function get_database($server, $user, $pass, $db)
{
mysql_connect($server, $user, $pass);
mysql_select_db($db);
$tables = mysql_query("show tables");
$delete = "";
while ($td = mysql_fetch_array($tables))
{
$table = $td[0];
$delete .= "DROP TABLE IF EXISTS $table;
";
$r = mysql_query("Show CREATE TABLE `$table`");
if ($r)
{
$insert_sql = "";
$d = mysql_fetch_array($r);
$d[1] .= ";";
$SQL[] = str_replace("\n", "", $d[1]);
$table_query = mysql_query("SELECT * FROM `$table`");
$num_fields = mysql_num_fields($table_query);
while ($fetch_row = mysql_fetch_array($table_query))
{
$insert_sql .= "INSERT INTO $table VALUES(";
for ($n=1;$n<=$num_fields;$n++)
{
$m = $n - 1;
$insert_sql .= "'".mysql_real_escape_string($fetch_row[$m])."', ";
}
$insert_sql = substr($insert_sql,0,-2);
$insert_sql .= ");\n";
}
if ($insert_sql!= "")
{
$SQL[] = $insert_sql;
}
}
}
$out = $delete.implode("\r", $SQL);
return $out;
}