| | |
PHP script to backup mysql
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
•
•
Join Date: Apr 2008
Posts: 495
Reputation:
Solved Threads: 0
Hi,
I am trying to backup one of my Mysql database with a PHP script.
Executed code works fine in Linux terminal (toy-10-09-2009-16:15:49.sql) but when i run this PHP script it doesn't work. No error too.
What do you think i miss?
Thanks
I am trying to backup one of my Mysql database with a PHP script.
PHP Syntax (Toggle Plain Text)
<?php $host="localhost"; $database="toy"; $username="root"; $password=""; $connection=mysql_connect($host, $username, $password); if(!$connection) { die("ERROR: Couldn't connect to the server."); } else { $dbSelect=mysql_select_db($database); if(!$dbSelect) { die("ERROR: Couldn't select the database."); } else { $mysqldumpPath="/usr/bin/mysqldump"; $backupFileName = "Desktop/toy-`date +%d-%m-%Y-%H:%M:%S`.sql"; $createBackup = $mysqldumpPath." -u ".$username." -h ".$host." ".$database." > ".$backupFileName; exec($createBackup); } } ?>
What do you think i miss?
Thanks
Last edited by veledrom; Sep 10th, 2009 at 12:34 pm. Reason: .
On this line:
You probably are going to need the absolute path to where the file needs to be stored.
PHP Syntax (Toggle Plain Text)
$backupFileName = "Desktop/toy-`date +%d-%m-%Y-%H:%M:%S`.sql";
Google is your friend.
Use [code] tags.
If you have found a solution to your problem, please mark the thread as SOLVED.
Use [code] tags.
If you have found a solution to your problem, please mark the thread as SOLVED.
No error. That's because you didn't echo the exec function. Line 18 should be as follows:
php Syntax (Toggle Plain Text)
echo exec($createBackup);
Try not to bump 10 year old threads as it can be really annoying.
Like php then read my website at http://syntax.cwarn23.net/
Star-Trek-Atlantis - now that's what I call a movie ^_^
My favourite PC. - MacGyver Fan
Bad english note: dis-iz-2b4u
Like php then read my website at http://syntax.cwarn23.net/
Star-Trek-Atlantis - now that's what I call a movie ^_^
My favourite PC. - MacGyver Fan
Bad english note: dis-iz-2b4u
•
•
Join Date: Apr 2008
Posts: 495
Reputation:
Solved Threads: 0
Still doesn't work. Also no error for
I changed the path to
As i said before, it works fine in Ubuntu terminal. I also, tar it in the terminal without any problem with same path.
Thanks
echo exec($createBackup);.I changed the path to
/usr/bin/mysqldump -u root -h localhost toy > /var/www/toy/toy-11-09-2009_10:03:41.sql but, still doesn't work in the script. As i said before, it works fine in Ubuntu terminal. I also, tar it in the terminal without any problem with same path.
Thanks
In Ubuntu. ok. I found this problem when I first got a Virtual Private Server. The server had a different file structure than what my Ubuntu did. So try to browse around your server to make sure those are the locations for your servers Operating System. There seems to be two mains sorts of systems of sorting files from my experience.
Try not to bump 10 year old threads as it can be really annoying.
Like php then read my website at http://syntax.cwarn23.net/
Star-Trek-Atlantis - now that's what I call a movie ^_^
My favourite PC. - MacGyver Fan
Bad english note: dis-iz-2b4u
Like php then read my website at http://syntax.cwarn23.net/
Star-Trek-Atlantis - now that's what I call a movie ^_^
My favourite PC. - MacGyver Fan
Bad english note: dis-iz-2b4u
•
•
•
•
Still doesn't work. Also no error forecho exec($createBackup);.
I changed the path to/usr/bin/mysqldump -u root -h localhost toy > /var/www/toy/toy-11-09-2009_10:03:41.sqlbut, still doesn't work in the script.
As i said before, it works fine in Ubuntu terminal. I also, tar it in the terminal without any problem with same path.
Thanks
Does your root account on mysql have no password? Just wondering...
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
•
•
•
•
Hi digital,
I don't know how to check if PHP has R+W privilages !!!
No password for MySQL. I didn't set it.
Thanks
eg:
PHP Syntax (Toggle Plain Text)
$result = file_put_contents('/var/www/toy/test.txt', 'hi'); var_dump($result);
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
•
•
Join Date: Apr 2008
Posts: 495
Reputation:
Solved Threads: 0
I have this info in 'User Settings'
Name-------Login name--------Home directory
veledrom ubuntu /home/ubuntu (this is active-bold and black coloured)
root root /root (this looks inactive-grey coloured)
This is what i did before.
ubuntu@ubuntu:~$ sudo chown -hR root /var/www/toy
I realise that i use root to login to mysql but in the terminal it shown ubuntu. Is ubuntu still root?
What can i do now? I bet it is something to do with users and permitions as you said, digital
Name-------Login name--------Home directory
veledrom ubuntu /home/ubuntu (this is active-bold and black coloured)
root root /root (this looks inactive-grey coloured)
This is what i did before.
ubuntu@ubuntu:~$ sudo chown -hR root /var/www/toy
I realise that i use root to login to mysql but in the terminal it shown ubuntu. Is ubuntu still root?
What can i do now? I bet it is something to do with users and permitions as you said, digital
![]() |
Similar Threads
- Help with php script to export mysql data and import data (PHP)
- question about connecting odbc to sql through php script (PHP)
- Please school me in PHP script installation. (MySQL)
- how to make member expire after so many days with php script (PHP)
- How many clients can access a PHP script at a time from a MySQL server? (MySQL)
- How many clients can access a PHP script at a time? (PHP)
Other Threads in the PHP Forum
- Previous Thread: uploading files with php
- Next Thread: PHP Editor Like Wordpress
| Thread Tools | Search this Thread |
apache api array beginner binary broken cache cakephp checkbox class cms code confirm cron curl customizableitems database date display dynamic echo email error external fcc file files folder form forms forum freelancing function functions google header headmethod howtowriteathesis href htaccess html iframe image include insert ip javascript joomla limit link login mail malfunction menu method mlm mod_rewrite multiple mysql neutrality oop pageing pagerank paypal pdf php phpmysql play problem query question radio random recursion remote root script search select server sessions sms soap source space sql support! syntax system table template tutorial update upload url validator variable video web youtube






