/    Sign up×
Community /Pin to ProfileBookmark

backup of db table using php

I’m trying to could backup one of tables from database using php only. I’d like to save result in some directory at my server or (the best) send it via e-mail.

My problem is that:
[B]exec()[/B] is disabled
[B]system()[/B] is disabled

I’m tried to use “[B]SELECT * INTO OUTFILE[/B]” and “[B]LOAD DATA INFILE[/B]” but I got blank page each time (no error raport). “[B]Backup[/B]” directory have [B]chmod 777[/B] so that’s not problem.

My files looks this way:

[code=php]
<?php

$host = “localhost”; // Host name
$username = “username”; // Mysql username
$password = “password”; // Mysql password
$db_name = “MyDbName”; // Database name
$tableName = “MyTestTable”; // Table name

// Connect to server and select database.
mysql_connect($host, $username, $password)or die(“cannot connect”);
mysql_select_db($db_name)or die(“cannot select DB”);

$backupFile = “/home/myusername/domains/mydomain.com/public_html/admin/backup/mybackup.sql”;
$query = “SELECT * INTO OUTFILE ‘$backupFile’ FROM $tableName”;
$result = mysql_query($query);

if($result){

echo “success”;

} else {

echo “error”;
}

// close connection
mysql_close();

?>
[/code]

[code=php]
<?php

$host = “localhost”; // Host name
$username = “username”; // Mysql username
$password = “password”; // Mysql password
$db_name = “MyDbName”; // Database name
$tableName = “MyTestTable”; // Table name

// Connect to server and select database.
mysql_connect($host, $username, $password)or die(“cannot connect”);
mysql_select_db($db_name)or die(“cannot select DB”);

$backupFile = “/home/myusername/domains/mydomain.com/public_html/admin/backup/mybackup.sql”;
$query = “LOAD DATA INFILE ‘backupFile’ INTO TABLE $tableName”;
$result = mysql_query($query);

if($result){

echo “success”;

} else {

echo “error”;
}

// close connection
mysql_close();

?>
[/code]

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@ilbonparaurtiMay 04.2010 — Getting a blank page sounds like php is encountering an error that is being suppressed.

Add the following to the start of the script(s) and see if it shows anything:
[code=php]ini_set('display_errors','On');[/code]
Copy linkTweet thisAlerts:
@HelleshternauthorMay 04.2010 — I have turned on all display_errors options but it doesn't show anything - blank page (with my "error" message).

[EDIT]

I use [B]PHP 5.2[/B] but I have possibility to use also other version. The result is it shows blank page under: [B]PHP 4[/B], [B]PHP 5.2[/B], [B]PHP 5.3.2[/B]. Under [B]PHP 6[/B] it shows error:


Warning: PHP Startup: htscanner: Unable to initialize module Module compiled with module API=20060613 PHP compiled with module API=20070729 These options need to match in Unknown on line 0

Warning: PHP Startup: magickwand: Unable to initialize module Module compiled with module API=20060613 PHP compiled with module API=20070729 These options need to match in Unknown on line 0

X-Powered-By: PHP/6.0.0-dev Content-type: text/html; charset=UTF-8 error[/QUOTE]
×

Success!

Help @Helleshtern spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...