Error Object of class daoMaterias could not be converted to string in daoMaterias.php on line 33

1

At the time of calling the function to register materials I encounter this error: Object of class daoMaterias could not be converted to string, Does anyone know how to solve?

class daoMaterias
    {

        private $pdo;


            /* Função para cadastrar materias */


            public function cadastrarMaterias($nome, $mediaMinima){


                $this->pdo = new conexao();

                $cadastrarMaterias = $this->pdo->conectar()->prepare("INSERT INTO  materias (id, nome, mediaMinima) VALUES (NULL, ?, ?)");

                $cadastrarMaterias->bindValue(1, $nome);

                $cadastrarMaterias->bindValue(2, $mediaMinima);

                $cadastrarMaterias->execute();

                session_start();

                if($cadastrarMaterias->rowCount() > 0 )
                {
                    $_SESSION["cadastrarMaterias"] = "Matéria cadastrada com sucesso ! " ;
                }else{
                    $_SESSION["cadastrarMaterias"] = "Erro ao cadastrar matéria";
                }
            }

This would be line 33: $cadastrarMaterias->bindValue(1, $nome);

    
asked by anonymous 28.10.2016 / 05:21

1 answer

1

The error message indicates that you are assigning an object as a string.

Example that simulates the error:

<?php

$x = (object)array(); // objeto para teste

//echo $x; //provoca o erro

$y = 'foo'.$x; // também provoca o erro

Go on line 33, a line before and add a test breakpoint

var_dump($nome); exit;
$cadastrarMaterias->bindValue(1, $nome); 

With this you can see what is loaded in the $nome variable.

    
28.10.2016 / 06:00