我目前正在使用嵌套集模型,并且我已经阅读了 MySQL 站点上的文章(Managing Hierarchical Data in MySQL)。
我直接从文章中得到以下查询:
LOCK TABLE categories WRITE;
SELECT @myRight := right FROM categories WHERE name = ?;
UPDATE categories SET right = right + 2 WHERE right > @myRight;
UPDATE categories SET left = lft + 2 WHERE left > @myRight;
INSERT INTO categories (name, left, right) VALUES(?, @myRight + 1, @myRight + 2);
UNLOCK TABLES;
我正在使用 PHP 和 MySQLi 函数来执行此语句,如下所示:
if (false !== $stmt = $mysqli->prepare($query)) {
$stmt->bind_param('ss', 'services', 'hosting');
$stmt->execute();
$stmt->close();
} else {
echo $mysqli->error;
}
以下代码产生语法错误:
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 'SELECT @myRight := right FROM categories WHERE name = ?; UPDATE categories SET righ' at line 3
我希望有人可以帮助我。