I have a website using PDO for connecting to a MySQL database and i'm trying to improve its security.
After reading this post, i added the line $dbConnection->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
so the connection lines are now like this:
$this->conn = new PDO("mysql:host=localhost;dbname=dbname;charset=utf8mb4", "user", "pass");
$this->conn->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
$this->conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
After this change, the website's PHP functions appear to work fine, with the exception of this one:
function resetidserials($table,$id){
$sql = "SET @num := 0;
UPDATE ".$table." SET ".$id." = @num := (@num+1);
ALTER TABLE ".$table." AUTO_INCREMENT = 1;";
$smt = $this->conn->prepare($sql);
$smt->execute();
}
This function is used to reset the auto increment ID numbers when a row is deleted. When the line $this->conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
is not present it works as expected, when it is present i get a syntax error. Why it doesn't work and how can i get it working with the line present? Thanks in advance