DB 2 SQL code


A PHP file that connects to a specified host and mySQL database, and generates the SQL queries needed to reconstruct the database. Very useful if you want to back up a database over the web, or simply to transfer a mySQL database to your local machine.

Features/Options:

-backup either structure, data, both or just test connection
-backup only specified tables or all
-view all databases
-suports multi-column keys, all field types, autoinc fields, etc.
-escapes all field data
-saves as db_name.sql
-fully functionalised to allow for easy customisation

download PHP source
 
 

Screenshot:
DB2SQL screenshot

Generated SQL Sample:

#    db2SQL v1.04 - puremango.co.uk
#---------------------------------------------
# Dump of Host: [localhost:3306]
#           DB: [puremang_mango]
#    Generated: August 5th, 2005, 6:18:25 am
#---------------------------------------------

#
# Structure of table [test_table]
#
CREATE TABLE IF NOT EXISTS test_table (

  id int(10) unsigned NOT NULL auto_increment ,
  date varchar(20) ,
  page varchar(255) ,
  remote_addr varchar(15) ,
  note varchar(255) ,
  PRIMARY KEY (id),
  UNIQUE KEY id (id),
   KEY id_2 (id)
);

#
# Data for [test_table]
#
INSERT INTO test_table VALUES(1,"20-03-05","index.php",".254","");
INSERT INTO test_table VALUES(2,"20-03-05","about.php",".254","");

Related Posts:

, , , ,

  1. #1 by M4rL on June 13, 2009 - 8:47 am

    can this be used to get database on a suspended site?

    • #2 by user24 on June 14, 2009 - 1:44 am

      If you know the hostname of the database server, and if they (your hosting company) allow connections from outside their network (which they sometimes do) then yes you should be able to use it to backup databases on suspended sites.
      Reason being that they probably just turned off your web site, but left the database credentials intact. Good luck, let us know if it works!

  2. #3 by M4rl on June 14, 2009 - 12:30 pm

    I tried the script, uploaded it on the same server where the suspended site is but it won’t let me in. :(

    • #4 by user24 on June 14, 2009 - 11:31 pm

      No, it won’t work for your purposes if you upload it to the same server – if they’ve disabled the site you wouldn’t be able to access the DB2SQL script; you’ll need to either use it locally (eg via wamp) or from another server.

  3. #5 by M4rl on June 17, 2009 - 4:40 pm

    i mean on the same server w/ a differnt account. no luck. thanks for the script though.

  4. #6 by Don on July 3, 2009 - 3:20 pm

    where do you download??

    • #7 by user24 on July 3, 2009 - 11:01 pm

      Where it says “download PHP source” :0)

  5. #8 by Layric on April 22, 2010 - 11:46 am

    i am run this file on localhost above screenshot not appear, all of file code print.
    why ?

    • #9 by Howard Yeend on April 22, 2010 - 11:46 pm

      You probably need to change the first line from:

      <?

      to

      <?php

Comments are closed.