Not signed in (Sign In)

Categories

Vanilla 1.1.5 is a product of Lussumo. More Information: Documentation, Community Support.

Help keep Vanilla free:
Welcome Guest!
Want to take part in these discussions? If you have an account, sign in now.
If you don't have an account, apply for one now.
  1.  # 1
    Running a query in phpmyadmin works, but same query run by mysql_query() function in php fails.

    The php code is this
    AddChildNode();
    function AddChildNode() {
    mysql_query('LOCK TABLE tree WRITE;

    SELECT @myLeft := lft FROM tree
    WHERE CategoryID = 2;

    UPDATE tree SET rgt = rgt + 2 WHERE rgt > @myLeft;
    UPDATE tree SET lft = lft + 2 WHERE lft > @myLeft;

    INSERT INTO tree(Name, lft, rgt) VALUES("FRS", @myLeft + 1, @myLeft + 2);

    UNLOCK TABLES;');

    }
    $result = mysql_query('SELECT Name, lft, rgt FROM tree;');
    while ($row = mysql_fetch_array($result)) {
    echo $row['Name'].' '.$row['lft'].' '.$row['rgt']."\n";
    }


    If u want to test here is the table
    CREATE TABLE `tree` (
    `CategoryID` int(5) NOT NULL auto_increment,
    `Name` varchar(100) NOT NULL default '',
    `lft` int(5) NOT NULL,
    `rgt` int(5) NOT NULL,
    PRIMARY KEY (`CategoryID`)
    ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=5 ;


    INSERT INTO `tree` VALUES (1, 'Parent1', 1, 2);
    INSERT INTO `tree` VALUES (2, 'Parent2', 3, 4);
    INSERT INTO `tree` VALUES (3, 'Parent3', 5, 6);
    INSERT INTO `tree` VALUES (4, 'Parent4', 7, 8);


    Is there some special syntax that i have to use with mysql_query?
  2.  # 2
    the error i get is this
    Error: 1064 Invalid query: 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 @myLeft:=lft FROM tree WHERE CategoryID=2;
    UPDATE tree SET rgt=rgt+2 WH' at line 1


    I don't see whats wrong with the syntax and phpmyadmin runs it without complaining.
  3.  # 3
    Never mind it cannot take multiple lines.
    I have to run each line separately. then it works
Add your comments
    Username Password
  • Format comments as