简体   繁体   English

用PDO和准备好的语句更改MySQL表

[英]Alter MySQL table with PDO and prepared statement

I've used PDO in my project with PHP and MySQL. 我在我的PHP和MySQL项目中使用了PDO。 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. 我想用PDO准备的语句更改表。 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; 致命错误:消息为“ SQLSTATE [42000]”的未捕获的异常“ PDOException”:语法错误或访问冲突:1064 SQL语法有错误; check the manual that corresponds to your MySQL server version for the right syntax to use near '?' 检查与您的MySQL服务器版本相对应的手册,以在'?'附近使用正确的语法。 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. 关于一般更改表-是的,大多数时候您无法绑定。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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