0

it is my first question here. if I am mistaken sorry for that.

I want, each user of my site, can backup their data from mysql. how can i do it using php?

something like that;

    <?php
$userid = 15;
$username = 'memmed';
$filename = $username.$userid.'sql';

$sql = 'SELECT * FROM users WHERE id = 15;';
$query = mysql_query($sql);
$row = mysql_fetch_row($query);
$text = 'INSERT INTO users (id, name, .. , ......) VALUES('.$row['id'].', ............)';

$handle = fopen('backups/'.$filename,'w+');

fwrite($handle,$text);
fclose($handle); ?>

2 Answers 2

0

The code you have given will not do "data backup" It will just do something like save the $text.

If you want to do mysql backup, try something like

mysql dump using php script

Sign up to request clarification or add additional context in comments.

1 Comment

I want just for some column backup
-1

just create 2 string as follow

$str1='';
$str2='';
    foreach($row as $key=>$value){
                $str1.=$key.',';
                $str2.="'".$value."',";
            }
        }
        $str1=rtrim($str1,',');
        $str2=rtrim($str2,',');

   $text = 'INSERT INTO users ('.$str1.') VALUES('.$str2.')';

1 Comment

This does not answer the question

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.