0
Good morning everyone, I have a doubt and I found nothing similar that can help me, I need to create a copy and put function or duplicate everything this information and generates a new ID keeping the information.
I’m doing a project listing and control system for the company I work for, following a table where I need the fields to be duplicated.
CREATE TABLE `tb_projetos` (
`id` int(11) NOT NULL,
`empresa` varchar(128) NOT NULL,
`nome` varchar(128) NOT NULL,
`tipo` varchar(128) NOT NULL,
`localidade` varchar(128) NOT NULL,
`aceitacao_projeto` varchar(128) NOT NULL,
`prazo_projeto` varchar(128) NOT NULL,
`mub_colaborador` varchar(128) NOT NULL,
`mub_inicio` varchar(128) NOT NULL,
`mub_fim` varchar(128) NOT NULL,
`lev_colaborador` varchar(128) NOT NULL,
`lev_inicio` varchar(128) NOT NULL,
`lev_fim` varchar(128) NOT NULL,
`dig_colaborador` varchar(128) NOT NULL,
`dig_inicio` varchar(128) NOT NULL,
`dig_fim` varchar(128) NOT NULL,
`cal_colaborador` varchar(128) NOT NULL,
`cal_inicio` varchar(128) NOT NULL,
`cal_fim` varchar(128) NOT NULL,
`art_trt` varchar(128) NOT NULL,
`engenheiro` varchar(128) NOT NULL,
`doc_colaborador` varchar(128) NOT NULL,
`doc_data` varchar(128) NOT NULL,
`doc_fim` varchar(128) NOT NULL,
`rev_colaborador` varchar(128) NOT NULL,
`rev_data` varchar(128) NOT NULL,
`doc_envio_colaborador` varchar(128) NOT NULL,
`doc_envio_envio` varchar(128) NOT NULL,
`doc_envio_entrega` varchar(128) NOT NULL,
`doc_envio_aprovacao` varchar(128) NOT NULL,
`protocolo_ei` varchar(128) NOT NULL,
`situacao` varchar(128) NOT NULL,
`concessionaria` varchar(128) NOT NULL,
`observacao` varchar(256) NOT NULL,
`adicionado` date NOT NULL,
`modificado` date DEFAULT NULL
)
making some tests, I arrived at this formula that when testing in the bd works but in the interpretation of the code it does not execute correctly.
include('../../class/db_conexao.php'); $id = 0;
$conexao->query("CREATE TEMPORARY TABLE tmp SELECT * FROM tb_projetos WHERE id=$id;") or die($conexao->error);
$conexao->query("UPDATE tmp SET id=$id+1 WHERE id = $id;") or die($conexao->error);
$conexao->query("INSERT INTO tb_projetos SELECT * FROM tmp WHERE id=$id+1;") or die($conexao->error);
suppose the table has only "id, company, name", would make a
insert into tabela (id, empresa, nome) select 1 as novoid, empresa, nome from tabela
simple, just for all fields and Where you need and of course change the value of "novoid", for example "id + 1000 as novoid"– Ricardo Pontual
hi, all good. I made a test here with an example on the internet and put it directly by mysql and it worked but tried to interpret in the code and it does not generate the copy.
include('../../class/db_conexao.php');

$id = 0;
$conexao->query("CREATE TEMPORARY TABLE tmp SELECT * FROM tb_projetos WHERE id=$id;") or die($conexao->error);
$conexao->query("UPDATE tmp SET id=$id+1 WHERE id = $id;") or die($conexao->error);
$conexao->query("INSERT INTO tb_projetos SELECT * FROM tmp WHERE id=$id+1;") or die($conexao->error);
– Augusto Santos