LOCK TABLE test WRITE;
SELECT @myRight := rgt FROM test
WHERE parent = 'AC';
UPDATE test SET rgt = rgt + 2 WHERE rgt > @myRight;
UPDATE test SET lft = lft + 2 WHERE lft > @myRight;
INSERT INTO test(produktas, lft, rgt, parent, level) VALUES('qwe', @myRight + 1, @myRight + 2, '', '');
UNLOCK TABLES
Bandau įvykdyt komandą per PHP - meta klaidą:
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 := rgt FROM test WHERE parent = 'AC'; UPDATE test SET rg' at line 2
Bet įvykdžius tiesiai per phpMyAdmin - viskas puikiai veikia. Kas čia negerai?
EDIT:
Na, jau supratau, kad su mysql_query keleto užklausų neįmanoma padaryti. Reik daryt su mysqli_multi_query, bet kažko taip pat nenori veikt...
mysqli_multi_query($con, "LOCK TABLE test WRITE;
SELECT @myRight := rgt FROM test
WHERE parent = '$cat';
UPDATE test SET rgt = rgt + 2 WHERE rgt > @myRight;
UPDATE test SET lft = lft + 2 WHERE lft > @myRight;
INSERT INTO test(produktas, lft, rgt, parent, level) VALUES('$produktas', @myRight + 1, @myRight + 2, '', '');
UNLOCK TABLES") or die(mysql_error());
Warning: mysqli_multi_query() expects parameter 1 to be mysqli, null given in C:\xampp\htdocs\skelbiu\config.php on line 136
$con = mysqli_connect($host, $user, $pw, $db);