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

Asked

Viewed 283 times

1

At the time of calling up the posting function I find 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";
                }
            }

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

1 answer

1


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

Example simulating the error:

<?php

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

//echo $x; //provoca o erro

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

Go to line 33, one line before and add a breakpoint for testing

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

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

Browser other questions tagged

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