logo
Tags down

shadow

PHP mysqldump database to sql file


By : Pedro Patusco
Date : May 05 2020, 09:55 AM

I need to export data (only the data, not the tables nor database) from the database to a mySQL file and save it. How to write a PHP function that does that? I want to call this function in specific circumstances when running specific queries (updating a blog post, for example).

Something like:

/*
* Get the data from the database (already specified) and export it to a SQL file
*
* @param  string $dir Where to store the SQL file. Must be a full path.
* @return void
*/
function export_database_data(string $dir) {
  // some code that gets the data and store it in $data
  // don't know what to do here

  // create/update the file
  file_put_contents("$dir/data_backup.sql", $data);
}


I try to do that because I want to have a backup of the data (only the data; the tables do not matter because I already know how to handle them for backup).

I'm do this because I will use the PHP function exec to run git commands and commit the change in the SQL file. The end goal is to keep track of the data in the database, which won't be updated often. I need the data in a SQL file and I aim to use git because it is easy to access and to collaborate with others (I could not think a better solution, and creating my own tracking system would require a lot of work and time).

Answer :

You can use a mysqldump command using PHP exec function to only export data.

example :

exec('mysqldump -u [user] -p[pass] --no-create-info mydb > mydb.sql');

More info:



Share : facebook icon twitter icon
Related Posts Related Posts :
  • clear array after form submit
  • pass url variable to javascript
  • access data using api
  • div position fixed css
  • add horizontal line between two div
  • disable toggle button css
  • css fixed line height
  • background image not working
  • table cell border
  • text line break css
  • overlay div on div
  • text direction rtl css
  • javascript convert string to an object
  • bind inner div click to outer div
  • jquery ajax oncomplete
  • how to use promise in for loop
  • jquery get element using variable
  • javascript send textbox value
  • pass div class content to another class or id
  • css new line after element
  • css calc not working properly
  • link disabled jquery
  • sql join table to subquery
  • MS Access SQL Issue with OR AND Operators
  • set textarea value using php
  • php merge two arrays into one
  • php form with google captcha
  • update current row in php
  • php date format mysql
  • mysql pdo select query
  • php function return an array
  • display image query
  • php create array using foreach loop
  • associative array php
  • group_concat in mysql laravel
  • php array_push empty
  • mysql on update cascade not working
  • pdo insert prepared statement
  • mysql insert ignore vs on duplicate key
  • mysql insert into existing row
  • mysql multi insert query
  • mysql group by show all rows
  • php change profile image
  • combine multiple arrays into one array php
  • how to sum values in an array
  • how to get sum of the total time
  • How to Create Facebook live stream without notification using API ?
  • on button click make div visible
  • css affect another element on hover
  • insert line after paragraph word
  • shadow
    Privacy Policy - Terms - Contact Us © bighow.org