Ver Mensaje Individual
  #14 (permalink)  
Antiguo 20/05/2011, 09:52
Avatar de memoadian
memoadian
Colaborador
 
Fecha de Ingreso: junio-2009
Ubicación: <?php echo 'México'?>
Mensajes: 3.696
Antigüedad: 14 años, 10 meses
Puntos: 641
Respuesta: crear mas de una tabla para la base de datos

ese fue error mio. XD

Código PHP:
Ver original
  1. <?php
  2.     $nombre_bd = 'prueba';
  3.     $conectar = mysql_connect("localhost", "root", "cyDsCr2dMTYRCjaa");
  4.     if (!$conectar) {
  5.         echo "No se ha podido conectar al servidor";
  6.     } else {
  7.         $crear = mysql_query("CREATE DATABASE $nombre_bd", $conectar);
  8.         $sql = "CREATE TABLE " . $nombre_bd . ".productos (`foto_id` int(11) NOT NULL AUTO_INCREMENT,
  9.  `producto` varchar(100) NOT NULL DEFAULT '',
  10.  `nombre` varchar(100) NOT NULL DEFAULT '',
  11.  `descripcion` char(65) NOT NULL,
  12.  `precio` double NOT NULL DEFAULT '0',
  13.  PRIMARY KEY (`foto_id`)
  14. ) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=46 ;
  15. ";
  16.         $sql2 = "CREATE TABLE " . $nombre_bd . ".tabla2 (`foto_id` int(11) NOT NULL AUTO_INCREMENT,
  17.  `producto` varchar(100) NOT NULL DEFAULT '',
  18.  `nombre` varchar(100) NOT NULL DEFAULT '',
  19.  `descripcion` char(65) NOT NULL,
  20.  `precio` double NOT NULL DEFAULT '0',
  21.  PRIMARY KEY (`foto_id`)
  22. ) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=46 ;
  23. ";
  24.         $sql3 = "CREATE TABLE " . $nombre_bd . ".tabla3 (`foto_id` int(11) NOT NULL AUTO_INCREMENT,
  25.  `producto` varchar(100) NOT NULL DEFAULT '',
  26.  `nombre` varchar(100) NOT NULL DEFAULT '',
  27.  `descripcion` char(65) NOT NULL,
  28.  `precio` double NOT NULL DEFAULT '0',
  29.  PRIMARY KEY (`foto_id`)
  30. ) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=46 ;
  31. ";
  32.     $correr = mysql_query($sql, $conectar);
  33.     $correr = mysql_query($sql2, $conectar);
  34.     $correr = mysql_query($sql3, $conectar);
  35.     }
  36. ?>

por no probar los códigps antes de postearlos

Cita:
De todas formas no creo que sea lo mejor crear una BD por usuario, imagínate las miles de BD que podrías llegar a tener.
eso mismo dije yo

Última edición por memoadian; 20/05/2011 a las 11:33