• home
  • forum
  • my
  • kt
  • download
  • Code/Script to Copy MySql Database

    Author: 2009-03-08 09:09:08 From:

    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<count($table_names);$i++){
    		mysql_query("create table ".$table_names[$i]." select * from $source_db.".$table_names[$i]);
    	}
     
    	echo count($table_names)." tables successfully copied!";
    ?>

    discuss this topic to forum

    relation tutorial

    No information

    Category

      Ad Management (6)
      Calendars (3)
      Chat Systems (8)
      Content Management (41)
      Cookies and Sessions (12)
      Counters (15)
      Database Related (23)
      Date and Time (13)
      Development (19)
      Discussion Boards (8)
      E Commerce (8)
      Email Systems (13)
      Error Handling (7)
      File Manipulation (24)
      Flash and PHP (6)
      Form Processing (19)
      Guestbooks (12)
      Image Manipulation (21)
      Installing PHP (7)
      Introduction to PHP (23)
      Link Indexing (8)
      Mailing List Management (9)
      Miscellaneous (53)
      Networking (8)
      News Publishing (9)
      OOP (24)
      PEAR (6)
      PHP vs Other Languages (2)
      Polls and Voting (6)
      Postcards (1)
      Randomizing (14)
      Redirection (11)
      Searching (9)
      Security (29)
      Site Navigation (16)
      User Authentication (14)
      WAP and WML (7)
      Web Fetching (8)
      Web Traffic Analysis (15)
      XML and PHP (16)

    New

    Hot