1

I try to save my database in PHP but not work its work only with Shell

With shell (work good)

mysqldump --user=root --password= --host=localhost site > C:\xamppp\htdocs\site\sql\tests.sql

With php (file is created but empty)

system('mysqldump --user=root --password= --host=localhost site > C:\xamppp\htdocs\site\sql\test.sql', $result);

for $result i have 1

I work with XAMP on Windows 7, i test exec and system but its same Thanks you

Cœur
  • 37,241
  • 25
  • 195
  • 267
p4c
  • 153
  • 2
  • 12

2 Answers2

2
$return_var = NULL;
$output = NULL;
$command = "mysqldump -u mysql-user -h your_host -pmysql-pass database_name > /directory_path/file.sql";
exec($command, $output, $return_var);

or you can refer to this answer mysqldump via PHP

Community
  • 1
  • 1
Oli Soproni B.
  • 2,774
  • 3
  • 22
  • 47
  • 1
    Thanks the path with PHP its not correct now its work with `C:\xamppp\mysql\bin\mysqldump` – p4c May 30 '15 at 15:56
1

Use 2>&1

<?php system("mysqldump --user=root --password= --host=localhost site > C:\xamppp\htdocs\site\sql\test.sql 2>&1", $result); ?>
e-Learner
  • 517
  • 1
  • 4
  • 15