Zend Database Adapter - MySQL Complex Query

I defined a function in my navigation model that executes the request, and I was wondering if there is a way to generate / execute the "Zendy" request. The query I used was suggested by Bill Karwin in another here to set a random recording order. I tried using a prepared statement, but the values ​​in the SIGN () function were quoted.

I am using a PDO adapter for MySQL.

/**
 *
 */
public function setPosition($parentId, $oldPosition, $newPosition)
{
    $parentId = intval($parentId);
    $oldPosition = intval($oldPosition);
    $newPosition = intval($newPosition);
    $this->getAdapter()->query("
        UPDATE `navigation`
        SET `position` = CASE `position`
            WHEN $oldPosition THEN $newPosition
            ELSE `position` + SIGN($oldPosition - $newPosition)
            END
        WHERE `parent_id` = $parentId
        AND `position` BETWEEN LEAST($oldPosition, $newPosition)
            AND GREATEST($oldPosition, $newPosition)
    ");
    return $this;
}
+1
source share
1 answer

Zend_Db_Select / Zend_Db_Expr, , , , , . - ZF , Zendy. .

, . , . , ZF-, . , , .

+4

Source: https://habr.com/ru/post/1748381/


All Articles