Update with generic CRUD

Asked

Viewed 134 times

0

I’m using a generic CRUD developed by William F. Milk and suits me very well, but I’m having a hard time making a change, I’ve tried some possibilities but without success, what I have is this:

// INSTANCIO A TABELA
$crud = Crud::getInstance($pdo, 'ubsSeq');

// BUSCO A ÚLTIMA SEQUÊNCIA DA TABELA
$sqlSeq = "SELECT max(valor) AS Sequencia FROM ubsSeq WHERE nome = 'seq_laudo'";
$arrayParamSeq = array();
$ResSeq = $crud->getSQLGeneric($sqlSeq, $arrayParamSeq, TRUE);

foreach ($ResSeq as $Seq) { 

    // ATRIBUO + 1 A SEQUÊNCIA RESGATADA
    $Seq = $Seq->Sequencia + 1;         

    // AQUI ALTERO O VALOR DA SEQUÊNCIA
    $arrayUp = array('Valor' => $Seq);  
    $arrayCond = array('Nome=' => 'seq_laudo');  
    $resposta = $crud->update($arrayUp, $arrayCond);    

}

The variable $Seq = $Seq->Sequencia + 1; is at the right value, but I can’t do the update, the attempt I made was to quote the variable $seq as it will be stored in a field varchar, but it didn’t work either.

  • Ever tried cast for string? Ex.: $arrayUp = array('Valor' => (string)$Seq);

  • Hello @Thomas, this attempt I had not yet tested, I just did and still could not, thanks for the tip.

  • One thing I just realized is in $arrayCond which must be the condition of the WHERE: the name of the field is same Nome=? I think you put one = after the field name

  • I also think the constraint is $arrayCond = array('Name=' => 'seq_laudo'); should be $arrayCond = array('Name' => 'seq_laudo'); I think it is also not advisable to change the value of the variable foreach $Seq in my opinion should use another variable to manipulate the value Sequence

  • Hello @Tiagogomes, according to the author’s documentation the syntax is the same, even have another change routine that works normally, but in this case no, thanks for the tips.

  • @adventistapr What is the result you were hoping for and what are you getting? What is the value of Valor in the bank after the foreach executes?

  • No select you use nome and the update is using Nome, already checked if the column name could be case-sensitive?

  • Hello person, the line $reply = $crud->update($arrayUp, $arrayCond); is giving me as a result 'false' and conseguente mind the field Value is not being updated.

Show 3 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.