-5

i am working on a project, and i will like to run a php script that will run as a backup. that is a script that will extract or export my database and send it to my mail. but what am confuse about is, can it be done using only php or sql or both?.

i will appreciate if you guys can help. Thanks

codedgift
  • 69
  • 7
  • 2
    I think the answer is basically YES – RiggsFolly Jun 05 '17 at 13:29
  • 2
    *"extract or export my database and send it to my mail."* ... I hope that #1 your database is really small and basic and #2 you're not saving any personal data in it - 'coz that sounds like a **really** bad idea to me. – CD001 Jun 05 '17 at 13:57

2 Answers2

-1

You can do both.

$output = 'backupDir/myData.sql';
$sql = "SELECT * INTO OUTFILE '$file' FROM `someTable`";
$res = mysql_query($sql);

You can execute the $sql separately on mysql client and get an output also.

Do check for permissions for backupDir directory. Sometimes they dont work with the webserver user www-data. Need to fix that also.

Umashankar Das
  • 601
  • 4
  • 12
-1

Yes of course you can do it using php. But it would be good if you will use shell for database exporting an keep the database backup on CDN. I think this link might be useful to export database using php script.

Export MySQL database using PHP only

Lokesh Jain
  • 579
  • 6
  • 19