Catchable fatal error: Object of class mysqli could not be converted to string

Asked

Viewed 448 times

1

I have a query from which when executing it, gives the following error:

Catchable fatal error: Object of class mysqli could not be converted to string

I confess that I never came across this error. All values are passing correctly. The code that is giving this error follows below:

mysqli_query(sprintf($this->conexao, "INSERT INTO cadastro_usuarios VALUES(null,0,'%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','A',NOW());", 
                mysqli_real_escape_string($this->conexao, $nome),
                mysqli_real_escape_string($this->conexao, $email),
                mysqli_real_escape_string($this->conexao, $dataNascimento),
                mysqli_real_escape_string($this->conexao, $endereco),
                mysqli_real_escape_string($this->conexao, $telefone),
                mysqli_real_escape_string($this->conexao, $celular),
                mysqli_real_escape_string($this->conexao, $apelido),
                mysqli_real_escape_string($this->conexao, $genero),
                mysqli_real_escape_string($this->conexao, $filhos),
                mysqli_real_escape_string($this->conexao, $site),
                mysqli_real_escape_string($this->conexao, $facebook),
                mysqli_real_escape_string($this->conexao, $instagram),
                mysqli_real_escape_string($this->conexao, $twitter),
                mysqli_real_escape_string($this->conexao, $nomeFoto),
                mysqli_real_escape_string($this->conexao, $descricao)));
  • 1

    The object $this->conexao must be the type string to work. The correct thing would be to remove it.

  • How careless my Valdeir. In fact he has to stay out of the sprintf. Thank you so much for paying attention to this detail.

1 answer

2


The object $this->conexao must be the type string to work. The correct thing would be to remove it.

The correct (in your code) is probably:

mysqli_query($this->conexao, sprintf("INSERT INTO cadastro_usuarios VALUES(null,0,'%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','A',NOW());", 
                mysqli_real_escape_string($this->conexao, $nome),
                mysqli_real_escape_string($this->conexao, $email),
                mysqli_real_escape_string($this->conexao, $dataNascimento),
                mysqli_real_escape_string($this->conexao, $endereco),
                mysqli_real_escape_string($this->conexao, $telefone),
                mysqli_real_escape_string($this->conexao, $celular),
                mysqli_real_escape_string($this->conexao, $apelido),
                mysqli_real_escape_string($this->conexao, $genero),
                mysqli_real_escape_string($this->conexao, $filhos),
                mysqli_real_escape_string($this->conexao, $site),
                mysqli_real_escape_string($this->conexao, $facebook),
                mysqli_real_escape_string($this->conexao, $instagram),
                mysqli_real_escape_string($this->conexao, $twitter),
                mysqli_real_escape_string($this->conexao, $nomeFoto),
                mysqli_real_escape_string($this->conexao, $descricao)));
  • Perfect Valdeir. It was an oversight of mine. Thank you so much for paying attention to this detail.

Browser other questions tagged

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