Error updating AUTO INCREMENT

2

I have the following code:

$sql='ALTER TABLE tributos_prod AUTO_INCREMENT=:ultimo_id';
try {
    $query_delete=$conecta->prepare($sql);
    $query_delete->bindValue('ultimo_id', $ultimo_idTP+1, PDO: : PARAM_STR);
    $query_delete->execute();
}
catch(PDOException $erro) {
    echo'[ERRO] ao atualizar AUTO-INCREMENTO: '.$erro->getMessage();
    exit;
}

The following error is displayed:

  

SQLSTATE [42000]: Syntax error or   access violation: 1064 You have an error in your SQL syntax; check the   manual that corresponds to your MySQL server version for the right   syntax to use near '' 13 '' at line 1

I already checked the value of the variable $ultimo_idTP , I used intval() and it's alright, but I'm not able to identify the problem.

    
asked by anonymous 18.07.2017 / 19:46

1 answer

2

Your parameter is being sent as a string by generating the syntax error according to the message: syntax to use near ''13'' .

To resolve this situation, enter the third argument as an integer ( PDO::PARAM_INT ).

Change:

$query_delete->bindValue('ultimo_id', $ultimo_idTP+1, PDO::PARAM_STR);

To:

$query_delete->bindValue('ultimo_id', $ultimo_idTP+1, PDO::PARAM_INT);
    
18.07.2017 / 19:51