0

I work with Medoo, MySQL Framework, when I try insert a new record, I can't but the pointer in the table increment. If I debug the sentence and execute the sentence in SQL Editor, works fine. MySQL engine is innoDB.

$db->insert("adicionales_clientes", [
   "categoria_adc" => 100,
   "fecha_adc" => $importante->data2_tab3default,
   "titulo_adc" => $importante->data1_tab3default,
   "tipo_adc" => 3,
   "cliente_adc" => $cliente,
]);
Hunter McMillen
  • 59,865
  • 24
  • 119
  • 170
  • 1
    You seem to have a trailing comma in your array. That will prevent it from running in PHP. Turn error checking on to see the error returned. – Sloan Thrasher May 22 '18 at 16:44
  • @HunterMcMillen, I know Javascript allows that, but I get errors when I have them in an array in PHP. – Sloan Thrasher May 22 '18 at 16:46
  • Do you mean "the `AUTO_INCREMENT` value goes up by one"? If so that's likely because it was allocated during a transaction that was rolled back. – tadman May 22 '18 at 16:47
  • @SloanThrasher https://stackoverflow.com/questions/2829581/why-do-php-array-examples-leave-a-trailing-comma – Hunter McMillen May 22 '18 at 16:49
  • Yes, the AUTO_INCREMENT value increase one. when i use the method debug in medoo, the sentence is: INSERT INTO adicionales_clientes (categoria_adc, fecha_adc, titulo_adc, tipo_adc, cliente_adc) VALUES ('100', '2018-05-03', 'qweqwe', '3', '5'), if i execute this query, works fine. – Abraham Pech May 22 '18 at 16:51
  • @HunterMcMillen: Thanks for the info! – Sloan Thrasher May 22 '18 at 17:21
  • Do you have a unique key on any of the values being inserted? – Sloan Thrasher May 22 '18 at 17:22
  • Only have a Primary Key in id field, is AUTO_INCREMENT, and no insert the value in the sentence. – Abraham Pech May 22 '18 at 17:27
  • If you say that the sql statement itself works fine, the problem seems to be in the rest of the code which you didnt share. If you are certain that you didnt get any (maybe supressed) error (which would be the most common case), I would check if you are maybe using a non-committed transaction (e.g. started a transaction without committing it, maybe indirectly by disabling autocommit mode). – Solarflare May 22 '18 at 19:25
  • Hi @Solarflare, thanks for your answer, I don't use transactions statement in my code (I should), i debug line for line and all works fine, even, the query is execute and I don't have error code, I share the rest of the code – Abraham Pech May 22 '18 at 19:54
  • `if(isset($importante->status)){ if($importante->status == 0){ $db->insert("adicionales_clientes", [ "categoria_adc" => 100, "fecha_adc" => $importante->data2_tab3default, "titulo_adc" => $importante->data1_tab3default, "tipo_adc" => 3, "cliente_adc" => $cliente ]); } }` – Abraham Pech May 22 '18 at 19:58
  • Well, I meant more the more general part of your code (e.g. a part that might start transactions/connection settings). Do you have other queries that work, that use the same way to execute, or are executed directly before/after that code? There are basically only three reasons the id gets incremented: a rollback, an error, or it is caused by another query. You have to figure out which it is (by some debugging, e.g. changing the statement to do something different and check if it works then, or by checking/adding the relevant code) – Solarflare May 23 '18 at 06:57

0 Answers0