Generate MySQL data dump in SQL from PHP

Posted by Álvaro G. Vicario on Stack Overflow See other posts from Stack Overflow or by Álvaro G. Vicario
Published on 2010-04-28T10:45:02Z Indexed on 2010/04/28 20:57 UTC
Read the original article Hit count: 201

Filed under:
|
|

I'm writing a PHP script to generate SQL dumps from my database for version control purposes. It already dumps the data structure by means of running the appropriate SHOW CREATE .... query. Now I want to dump data itself but I'm unsure about the best method. My requirements are:

  • I need a record per row
  • Rows must be sorted by primary key
  • SQL must be valid and exact no matter the data type (integers, strings, binary data...)
  • Dumps should be identical when data has not changed

I can detect and run mysqldump as external command but that adds an extra system requirement and I need to parse the output in order to remove headers and footers with dump information I don't need (such as server version or dump date). I'd love to keep my script as simple as I can so it can be hold in an standalone file.

What are my alternatives?

© Stack Overflow or respective owner

Related posts about php

Related posts about mysql