/    Sign up×
Community /Pin to ProfileBookmark

Copying database with php

Hi all

I am here again hoping to get some sought of help for the issue i ran into.

Is it possible to create a database by copying from an existing db by running a php script?

thnx and regds
salim

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@bokehSep 26.2007 — Yes!
Copy linkTweet thisAlerts:
@salimauthorSep 26.2007 — please brief how to do it
Copy linkTweet thisAlerts:
@bokehSep 26.2007 — You need to properly detail what you are trying to do.
Copy linkTweet thisAlerts:
@salimauthorSep 26.2007 — I am having a database called mydb.when the user runs a php page i want another database to be created same as the 'mydb'.user will enter the database name in a text box he wants to create.so new database will be created with that name.
Copy linkTweet thisAlerts:
@salimauthorOct 04.2007 — I am a lil late to post this.

I am posting this so that someday some one may find it usefull?

<?php

$localhost = "your_host";

$username = "user_name";

$password = "password";

$database = "database_name";//of which dump is to be created.


$backupFile = $database . date("Y-m-d-H-i-s") . '.sql';

$command = "mysqldump --opt -h $localhost -u $username $database > $backupFile";

system($command);

chmod($backupFile,0777);

//write the code here to connect to your database

$database_new = "my_new_database";//put the name of the database you want to create

$sql = 'CREATE DATABASE '.$database_new;//create new database

//now restore the dump to the newly created database.

$command_new = "mysql -h $localhost -u $username $database_new < $backupFile";

system($command_new);

?>
×

Success!

Help @salim spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.1,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...