0
What exactly does that mean?
Array
(
[0] => Array
    (
        [MAX(nr_ficha)] => 13
    )
)
I gave one print on the screen and saw that my foreign key (nr_ficha) is receiving value 13 (which yes, is the last value of the table), but I do not understand the rest of the code nor why it does not work. 
Notice: Array to string Conversion in C: xampp htdocs TESTE_BANCADA Models Teste.php on line 16
Fatal error: Uncaught Pdoexception: SQLSTATE[23000]: Integrity Constraint Violation: 1452 Cannot add or update a Child Row: a Foreign key Cont straint fails (
teste__bancada.teste, CONSTRAINTnr_ficha_testeFOREIGN KEY (nr_ficha) REFERENCEScab_teste(nr_ficha)) in C: xampp htdocs TESTE_BANCADA Models Teste.php:18 Stack trace: #0 C: xampp htdocs TESTE_BANCADA Models Teste.php(18): PDO->exec('INSERT INTO tes...') #1 C: xampp htdocs TEST_BANCADA Controllers processa_testeq.php(30): Teste->cadastrar_teste(Array, '4', '4', '1') #2 {main} thrown in C: xampp htdocs TESTE_BANCADA Models Teste.php on line 18
The function I used was this:
public function busca_ficha(){
$conexao = Database::getConnection();
$select="SELECT MAX(nr_ficha) FROM cab_teste";
  $busca = $conexao->query($select);
  $nr_ficha = $busca->fetchAll(PDO::FETCH_ASSOC);
  return $nr_ficha;
}
And I called her that:
$ficha = new Cabecalho();
$nr_ficha = $ficha->busca_ficha();
Somebody help me, Please.
Because it’s the return of
MySQLyou can name the field withAS, would look like this:$select="SELECT MAX(nr_ficha) AS apelido FROM cab_teste";. TheASmay also be implied, thus:$select="SELECT MAX(nr_ficha) apelido FROM cab_teste";.– Roberto de Campos
Did the answer solve your question? Do you think you can accept it? See [tour] if you don’t know how you do it. This would help a lot to indicate that the solution was useful to you. You can also vote on any question or answer you find useful on the entire site (when).
– Maniero