简体   繁体   中英

Alter MySQL table with PDO and prepared statement

I've used PDO in my project with PHP and MySQL. Everything is working fine, but I have an error on executing the code below:

$sql = "ALTER TABLE tbl_invoices AUTO_INCREMENT = ?";
$q = $db->prepare($sql);
$q->execute(array($invoice_start));  

I want to alter a table with PDO prepared statement. But I'm getting this error:

Fatal error: Uncaught exception 'PDOException' with message '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 '?' at line ...

I tested different solutions, but none of them could not solve it. Do you have any idea?

ALTER TABLE tbl_invoices AUTO_INCREMENT = ?

This is what you are doing wrong thin first place.

Never. Ever. Touch. The auto increment.

Any time you take it as a number, it means a severe flaw in the database design.

While regarding altering tables in general - yes, most of time you cannot bind.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM