mysqldump

This is a discussion on mysqldump within the PHP General forums, part of the PHP Programming Forums category; This is an attempt to create an backup script for my online databases. There are few things to sort out ...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 07-25-2003
Marios Adamantopoulos
 
Posts: n/a
Default mysqldump

This is an attempt to create an backup script for my online databases. There
are few things to sort out and the coding is not the most effiecient out
there yet!!!

I just wanted to check on what you guys think, am I going the right way, is
there anything I should keep in mind?

Mario

Code below
-----------------
<?php
$host = "localhost";
$user = "xxxxx";
$password = "xxxxx";
$database = "xxxxxx";
$field = "xxxxxxx";

$db_link = mysql_connect($host, $user, $password) or die ("error connect");
mysql_select_db($database,$db_link);
$query="DESC $field";
$results=mysql_query($query);

while ($row=mysql_fetch_array($results)) {

if ($row[3]=="PRI") {
$thepri = $row[0];
}
$thesql .= $row[0] . " " . $row[1];
if ($row[2]=="YES") {
$thesql .= " default NULL";
} else {
$thesql .= " NOT NULL";
}
$thesql .= " " . $row[5];
$thesql .= ", \n";
}
$thecreate = "CREATE TABLE " . $field . "_backup ( \n";
$thecreate .= $thesql;
$thecreate .= " PRIMARY KEY (" . $thepri . ")\n";
$thecreate .= ") TYPE=MyISAM;";
echo "The CREATE STATEMENT<br>";
echo $thecreate;
echo "<br>";
echo "<br>";

//==============================//
//======== INSERT CODE ==========//
//==============================//

$result = mysql_list_tables($database);

if (!$result) {
print "DB Error, could not list tables\n";
print 'MySQL Error: ' . mysql_error();
exit;
}
$z=1;
while ($row = mysql_fetch_row($result)) {
//***********************
//IMPROVEEEEEEEEE
//echo $row[0] . "\n<br>";
$z++;
}
//****************************************
//MAKE THE FOLLOWING DYNAMIC

$query2 = "SELECT * from " . $field;
$results=mysql_query($query2);

$m=0;
while ($row=mysql_fetch_array($results)) {


for ($i=0;$i<=$z-1;$i++) {
$x = $row[$i];
if (($i == 0) && ($m<>0)) {
$therest .= "),";
}
if ($i == 0) {
$therest .= "(";
}

if (!isset($x)) {
$x = "NULL";
} else {
$x = "'" . addslashes($x). "'";
}

if ($i<>0) {
$therest .= ",";
}

$therest .= $x;
}
$m++;
}
$therest .= ")";


echo "The INSERT STATEMENT<br>";
$theinsert = "INSERT INTO ". $field . "_backup VALUES ";
$theinsert .= $therest . ";";
echo $theinsert;
?>

Reply With Quote
  #2 (permalink)  
Old 07-25-2003
Curt Zirzow
 
Posts: n/a
Default Re: [PHP] mysqldump

* Thus wrote Marios Adamantopoulos (mario@tonic.co.uk):
> This is an attempt to create an backup script for my online databases. There
> are few things to sort out and the coding is not the most effiecient out
> there yet!!!
>
> I just wanted to check on what you guys think, am I going the right way, is
> there anything I should keep in mind?


perhaps something like would be a whole lot easier:
`mysqldump [options] db tables`;

My general policy is don't revent the wheel unless it isn't round.

Curt
--
"I used to think I was indecisive, but now I'm not so sure."
Reply With Quote
  #3 (permalink)  
Old 07-25-2003
David Smith
 
Posts: n/a
Default RE: [PHP] mysqldump

I agree with Curt, why reinvent the wheel. I mean even if you are like me
and cannot access the command-line on your web server (which really really
sucks) then there are still other tools that can do this very same thing. If
you just want to click on a link and backup the db why not use the load data
infile (of course this does not backup the database structure just the data)
http://www.mysql.com/doc/en/LOAD_DATA.html. Or why not just get phpMyAdmin
and upload it to your server. It already has these features plus many
others, and of course the best part is it is open source
http://sourceforge.net/projects/phpmyadmin/. So why take the time of
reinventing the wheel?
Of course this is just my dumb opinion...so you can always take it or leave
it.
David



-----Original Message-----
From: Curt Zirzow [mailto:curt@zirzow.dyndns.org]
Sent: Friday, July 25, 2003 10:33 AM
To: 'php-general@lists.php.net'
Subject: Re: [php] mysqldump


* Thus wrote Marios Adamantopoulos (mario@tonic.co.uk):
> This is an attempt to create an backup script for my online databases.

There
> are few things to sort out and the coding is not the most effiecient out
> there yet!!!
>
> I just wanted to check on what you guys think, am I going the right way,

is
> there anything I should keep in mind?


perhaps something like would be a whole lot easier:
`mysqldump [options] db tables`;

My general policy is don't revent the wheel unless it isn't round.

Curt
--
"I used to think I was indecisive, but now I'm not so sure."

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



Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 02:21 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0