I'm looking to create a database from a one-button event, the problem is that the way I'm doing it at the moment, is to take each query, add it manually and execute it, all right up there. The problem is that every time there is a change in the database (either in one of its tables, or some kind of data that has one of them int
, text
... etc) I have to go and make the manual change mind thing that takes me some time depending on the amount of changes that are made, I leave an example:
<?php
$mysql = new MySQL();
$mysql->conectar();
$mysql->ingresoRegistro("CREATE DATABASE MoltranAP_".$idEmpresa."BD");
//Creamos las tablas
//Table 'Electrificadora'
$query1 = "CREATE TABLE IF NOT EXISTS MoltranAP_".$idEmpresa."BD.Electrificadora (
'id' INT(11) NOT NULL AUTO_INCREMENT COMMENT '',
'nombre' VARCHAR(45) NOT NULL COMMENT '',
'estado' int(50) NOT NULL,
PRIMARY KEY ('id') COMMENT '',
UNIQUE INDEX 'nombre' ('nombre' ASC) COMMENT '')
ENGINE = InnoDB
AUTO_INCREMENT = 1
DEFAULT CHARACTER SET = latin1";
$mysql->ingresoRegistro($query1);
//Table 'ArchivoElectrificadora'
$query2 = "CREATE TABLE IF NOT EXISTS MoltranAP_".$idEmpresa."BD.ArchivoElectrificadora (
'id' int(11) NOT NULL AUTO_INCREMENT,
'fechaHora' datetime NOT NULL,
'fechaArchivo' date NOT NULL,
'nombre' varchar(100) NOT NULL,
'cantidadRegistros' int(11) NOT NULL,
'tipo' varchar(45) NOT NULL,
'zona' tinyint(4) NOT NULL,
'Electrificadora_id' int(11) NOT NULL,
PRIMARY KEY ('id'),
KEY 'fk_ArchivoElectrificadora_Electrificadora1_idx' ('Electrificadora_id')
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;";
$mysql->ingresoRegistro($query2);
$idEmpresa
is the id of a newly registered company and this will be the "differentiator" to say it in some way from the database that I will create, it would be something like that MoltranAP_1BD
.
the number of tables is around 30, my intention is to be able to import the script .sql
and extract the queries with this could save time.
Is it possible?