p4c
p4c

Reputation: 153

Mysqldump generate empty file in php

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

Upvotes: 1

Views: 687

Answers (2)

e-Learner
e-Learner

Reputation: 517

Use 2>&1

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

Upvotes: 1

Oli Soproni B.
Oli Soproni B.

Reputation: 2800

$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

Upvotes: 2

Related Questions