Just another WordPress.com site

Posts tagged ‘database’

Code/Script to Copy MySql Database

Need information about programming ? visit this site : agiptek.com

This is a very smart script to copy a mysql database (with contents) to another database or it simply duplicates/backups a mysql database

<?
// Change the source & destination database
// You don’t need to create the destination database, only change the name below

$source_db=”db1″;
$new_db=”db2″;

mysql_connect(“localhost”,”root”,””);
mysql_select_db($source_db);

$result=mysql_query(“show tables”);

$table_names=array();
while($row=mysql_fetch_array($result)){
$table_names[]=$row[0];
}

mysql_query(“create database $new_db”);
mysql_select_db($new_db);

for($i=0;$i