Is there something similar to this out there?

Is there something similar to this out there?

am 12.05.2007 04:52:12 von rieh25

I'm working on a script to create back-up's of a database. It's not complete
because it only generates the "insert into" commands, it doesn't generate
the "create database" or "create table" ones, but I wondered if there is
another way to create a back-up's of a database that can only be accessed
through the web.

Script (replace '[' and ']'):

[?php
$link = mysql_connect("127.0.0.1","root","password");
$bd = "my_database";
$result = mysql_listtables ($bd);
$i = 0;
while ($i [ mysql_num_rows ($result)) {
$tb_names[$i] = mysql_tablename ($result, $i);
$result_fields = mysql_db_query($bd, "desc ".$tb_names[$i]);
$j = 0;
$campos = array();
$tipos = array();
while ($field = mysql_fetch_array($result_fields)){
$campos[$j] = $field["Field"];
$tipos[$j++] = $field["Type"];
}
mysql_free_result($result_fields);
$result_query = mysql_db_query($bd, "select * from ".$tb_names[$i]);
if (mysql_num_rows($result_query) ] 0){
echo "DELETE * FROM ".$tb_names[$i] ."[br]";
echo "COMMIT;[br]";
echo "INSERT INTO ".$tb_names[$i] ."(";
echo join(", ", $campos).") VALUES[br]";
$l = 0;
$lineas = array();
while ($datos = mysql_fetch_array($result_query)){
$k = 0;
$linea = array();
while ($k [ $j){
if (is_null($datos[$k])){
$linea[$k] = "NULL";
} else {
$linea[$k] =
'"'.str_replace(chr(13).chr(10),"\\r\\n",$datos[$k]).'"';
}
$k++;
}
$lineas[$l++] = "(".join(", ", $linea).")";
}
echo join(",[br]", $lineas).";[br]COMMIT;[br][br]";
}
$i++;
mysql_free_result($result_query);
}
mysql_close($link);
?]
--
View this message in context: http://www.nabble.com/Is-there-something-similar-to-this-out -there--tf3730521.html#a10442248
Sent from the Php - Database mailing list archive at Nabble.com.

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Is there something similar to this out there?

am 12.05.2007 07:41:00 von bedul

u using echo on your script.. that's not wise
i suggest u save all your type on a var like $txt

and in the end of line u print it

that will save your work..

your problem was how to make CREATE?
it hard since i kinda bussy.. but hope i can help u..


----- Original Message -----
From: "rieh25"
To:
Sent: Saturday, May 12, 2007 9:52 AM
Subject: [PHP-DB] Is there something similar to this out there?


>
> I'm working on a script to create back-up's of a database. It's not
complete
> because it only generates the "insert into" commands, it doesn't generate
> the "create database" or "create table" ones, but I wondered if there is
> another way to create a back-up's of a database that can only be accessed
> through the web.
>
> Script (replace '[' and ']'):
>
> [?php
> $link = mysql_connect("127.0.0.1","root","password");
> $bd = "my_database";
> $result = mysql_listtables ($bd);
> $i = 0;
> while ($i [ mysql_num_rows ($result)) {
> $tb_names[$i] = mysql_tablename ($result, $i);
> $result_fields = mysql_db_query($bd, "desc ".$tb_names[$i]);
> $j = 0;
> $campos = array();
> $tipos = array();
> while ($field = mysql_fetch_array($result_fields)){
> $campos[$j] = $field["Field"];
> $tipos[$j++] = $field["Type"];
> }
> mysql_free_result($result_fields);
> $result_query = mysql_db_query($bd, "select * from ".$tb_names[$i]);
> if (mysql_num_rows($result_query) ] 0){
> echo "DELETE * FROM ".$tb_names[$i] ."[br]";
> echo "COMMIT;[br]";
> echo "INSERT INTO ".$tb_names[$i] ."(";
> echo join(", ", $campos).") VALUES[br]";
> $l = 0;
> $lineas = array();
> while ($datos = mysql_fetch_array($result_query)){
> $k = 0;
> $linea = array();
> while ($k [ $j){
> if (is_null($datos[$k])){
> $linea[$k] = "NULL";
> } else {
> $linea[$k] =
> '"'.str_replace(chr(13).chr(10),"\\r\\n",$datos[$k]).'"';
> }
> $k++;
> }
> $lineas[$l++] = "(".join(", ", $linea).")";
> }
> echo join(",[br]", $lineas).";[br]COMMIT;[br][br]";
> }
> $i++;
> mysql_free_result($result_query);
> }
> mysql_close($link);
> ?]
> --
> View this message in context:
http://www.nabble.com/Is-there-something-similar-to-this-out -there--tf373052
1.html#a10442248
> Sent from the Php - Database mailing list archive at Nabble.com.
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Is there something similar to this out there?

am 14.05.2007 04:00:31 von dmagick

rieh25 wrote:
> I'm working on a script to create back-up's of a database. It's not complete
> because it only generates the "insert into" commands, it doesn't generate
> the "create database" or "create table" ones, but I wondered if there is
> another way to create a back-up's of a database that can only be accessed
> through the web.

$qry = "SHOW CREATE TABLE " . $tablename;
$result = mysql_query($qry);
$create_table = mysql_result($result, 0, 1) . ";\n";

No idea about create database but something similar should work.

--
Postgresql & php tutorials
http://www.designmagick.com/

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php