Error in PDO embedded

Asked

Viewed 39 times

-2

Hello,

I have the following code:

public function insert($nome,$email,$senha,$cluster,$situacoes_id,$niveis_acesso_id,$empresa,$modified,$area,$escritorio,$contrato,$regional) {        

       $stmt = $this->pdo->prepare("INSERT INTO [dbo].Usuarios VALUES('$nome','$email','$senha','$cluster','$situacoes_id','$niveis_acesso_id',
       '$empresa','$modified','$area','$escritorio','$contrato','$regional')");

       $stmt->bindParam(':nome', $nome);
       $stmt->bindParam(':email', $email);
       $stmt->bindParam(':senha', $senha);
       $stmt->bindParam(':cluster', $cluster);
       $stmt->bindParam(':situacoes_id', $situacoes_id);
       $stmt->bindParam(':niveis_acesso_id', $niveis_acesso_id);
       $stmt->bindParam(':empresa', $empresa);
       $stmt->bindParam(':modified', $modified);
       $stmt->bindParam(':area', $area);
       $stmt->bindParam(':escritorio', $escritorio);    
       $stmt->bindParam(':contrato', $contrato);    
       $stmt->bindParam(':regional', $regional);    
       $stmt->execute();

       var_dump($stmt->errorInfo());

       if($stmt->rowCount() > 0) {
        echo "cadastro com sucesso";
    }
    else {
        echo "não foi cadastrado";
    }



}

is reporting this error:

array(3) { [0]=> string(5) "IMSSP" [1]=> int(-29) [2]=> string(84) "Tried to bind Parameter number 0. SQL Server Supports a Maximum of 2100 Parameters." } was not registered

  • According to the Error "SQL Server supports at most 2100 parameters."... You are trying to insert a very large value into the database.

  • I have already checked the data by editing the separation Insert in Sql Server and it works, in code that is not working.

  • I found something here, try the following: INSERT INTO [dbo].Usuarios VALUES($nome,$email,$senha,$cluster,$situacoes_id,$niveis_acesso_id,
 $empresa,$modified,$area,$escritorio,$contrato,$regional), Maybe taking out the ' works.

  • Build the query text in a similar way to: INSERT INTO [dbo]. Usuarios (name, email, ...outros_campos) values (:name, :email, ...:outros_campos)

  • You noticed that you set the values of the parameters, but in no time you use them in SQL? You used the variables directly instead of using the parameters.

  • I don’t understand, I’m not using in SQL?

Show 1 more comment

1 answer

0


Your query is misspelled:

$stmt = $this->pdo->prepare("INSERT INTO [dbo].Usuarios VALUES('$nome','$email','$senha','$cluster','$situacoes_id','$niveis_acesso_id',
       '$empresa','$modified','$area','$escritorio','$contrato','$regional')");

Parameters in a Prepared statement should start with colon and single quotes are unnecessary, even in char fields:

$stmt = $this->pdo->prepare("INSERT INTO [dbo].Usuarios VALUES(:nome,:email,:senha,:cluster,:situacoes_id,:niveis_acesso_id,
       :empresa,:modified,:area,:escritorio,:contrato,:regional)");
  • Ball show Julio, it worked!!!

Browser other questions tagged

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