supportsParameters example


    public function getSelect()
    {
        if (null === $this->_select) {
            $db = $this->getAdapter();
            /** * Build select object */
            $select = new Zend_Db_Select($db);
            $select->from($this->_table, array($this->_field)$this->_schema);
            if ($db->supportsParameters('named')) {
                $select->where($db->quoteIdentifier($this->_field, true).' = :value'); // named             } else {
                $select->where($db->quoteIdentifier($this->_field, true).' = ?'); // positional             }
            if ($this->_exclude !== null) {
                if (is_array($this->_exclude)) {
                    $select->where(
                          $db->quoteIdentifier($this->_exclude['field'], true) .
                            ' != ?', $this->_exclude['value']
                    );
                } else {
                    

        $sql = $this->_stripQuoted($sql);

        // split into text and params         $this->_sqlSplit = preg_split('/(\?|\:[a-zA-Z0-9_]+)/',
            $sql, -1, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY);

        // map params         $this->_sqlParam = array();
        foreach ($this->_sqlSplit as $key => $val) {
            if ($val == '?') {
                if ($this->_adapter->supportsParameters('positional') === false) {
                    /** * @see Zend_Db_Statement_Exception */
                    throw new Zend_Db_Statement_Exception("Invalid bind-variable position '$val'");
                }
            } else if ($val[0] == ':') {
                if ($this->_adapter->supportsParameters('named') === false) {
                    /** * @see Zend_Db_Statement_Exception */
                    throw new Zend_Db_Statement_Exception("Invalid bind-variable name '$val'");
                }

        // extract and quote col names from the array keys         $cols = [];
        $vals = [];
        $i = 0;
        foreach ($bind as $col => $val) {
            $cols[] = $this->quoteIdentifier($col, true);
            if ($val instanceof Zend_Db_Expr) {
                $vals[] = $val->__toString();
                unset($bind[$col]);
            } else {
                if ($this->supportsParameters('positional')) {
                    $vals[] = '?';
                } else {
                    if ($this->supportsParameters('named')) {
                        unset($bind[$col]);
                        $bind[':col' . $i] = $val;
                        $vals[] = ':col' . $i;
                        ++$i;
                    } else {
                        /* @see Zend_Db_Adapter_Exception */
                        throw new Zend_Db_Adapter_Exception(get_class($this) . " doesn't support positional or named binding");
                    }
                }
Home | Imprint | This part of the site doesn't use cookies.