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

1

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

  

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

I confess that I have never come 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)));
    
asked by anonymous 27.12.2017 / 00:18

1 answer

2

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

The correct one (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)));
    
27.12.2017 / 00:22