使用prepare语句时遇到一些问题,因为我之前从未使用过它.Bellow是我的代码
$maxid = $rowid['product_id'];
$reset = "ALTER TABLE streamyxup AUTO_INCREMENT = $maxid";
$stmt = $conn->PREPARE($reset);
$query->EXECUTE;
DEALLOCATE PREPARE stmt;
答案 0 :(得分:1)
您需要更改以下代码才能使用mysql prepared statement
$maxid = $rowid['product_id'];
$reset = "ALTER TABLE streamyxup AUTO_INCREMENT = ?";
$stmt = $conn->prepare($reset);
$stmt->bind_param("i", $maxid);
$stmt->execute();
修改强>
你正在混合面向对象和mysql的程序方式。更改您的连接代码如下
session_start();
$conn = new mysqli("103.6.xxx.xxx", "Miow", "xxow2!", "pe_tm");
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
答案 1 :(得分:0)
SELECT MAX(autoincrement_field) + 1 FROM streamyxup INTO @maxautoinc;
ALTER TABLE streamyxup AUTO_INCREMENT = @maxautoinc;
和
SELECT @max := MAX(ID)+ 1 FROM streamyxup;
PREPARE stmt FROM 'ALTER streamyxup ABC AUTO_INCREMENT = ?';
EXECUTE stmt USING @max;
DEALLOCATE PREPARE stmt;