Export mysql database tables to php code to create same tables in other database?

Posted by chefnelone on Super User See other posts from Super User or by chefnelone
Published on 2011-06-29T16:26:29Z Indexed on 2011/06/30 0:24 UTC
Read the original article Hit count: 552

Filed under:
|

How do I Export mysql database tables to php code so that it allows me to create and populate same tables in other database?

I have a local database, I exported to sql syntax, then I get something like:

CREATE TABLE `boletinSuscritos` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(120) NOT NULL,
  `email` varchar(120) NOT NULL,
  `date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=3 ;

INSERT INTO `boletinSuscritos` VALUES(1, 'walter', '[email protected]', '2010-03-24 12:53:12');
INSERT INTO `boletinSuscritos` VALUES(2, 'Paco', '[email protected]', '2010-03-24 12:56:56');

but I need it to be: (Is there any way to export the tables in this way)

$sql = "CREATE TABLE  boletinSuscritos  (
   id  int(11) NOT NULL AUTO_INCREMENT,
   name  varchar(120) NOT NULL,
   email  varchar(120) NOT NULL,
   date  timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY ( id )
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=3 )";

mysql_query($sql,$conexion);

 mysql_query("INSERT INTO boletinSuscritos  VALUES(1, 'walter', '[email protected]', '2010-03-24 12:53:12')");
 mysql_query("INSERT INTO boletinSuscritos  VALUES(2, 'Paco', '[email protected]', '2010-03-24 12:56:56')");

© Super User or respective owner

Related posts about php

Related posts about mysql