2

Is it possible to export the database with .sql Extension using PHP code?

Example

database name: demodb
DB contains two tables

table one: user

table two: registration

1
  • 1
    All you have to do is build CREATE and INSERT statements with your PHP code and put into your SQL file. Commented Jan 29, 2014 at 7:21

2 Answers 2

6

Yes Its possible .

 <?php
        //ENTER THE RELEVANT INFO BELOW
        $mysqlDatabaseName ='xxxxxx';
        $mysqlUserName ='xxxxxxx';
        $mysqlPassword ='myPassword';
        $mysqlHostName ='xxxxxxxx.net';
        $mysqlExportPath ='chooseFilenameForBackup.sql';

        //DO NOT EDIT BELOW THIS LINE
        //Export the database and output the status to the page
        $command='mysqldump --opt -h' .$mysqlHostName .' -u' .$mysqlUserName .' -p' .$mysqlPassword .' ' .$mysqlDatabaseName .' > ~/' .$mysqlExportPath;
        exec($command);
 ?>
Sign up to request clarification or add additional context in comments.

Comments

2

use mysqldump command for mySql db:

$command = "/usr/bin/mysqldump -u mysql_username -h mysql_host -p mysql_password database_name> /path_to_export_location/file_name.sql";
exec($command, NULL, NULL);

make a look at documentation in MySQL

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.