Zend_Db_Adapter_Pdo_Abstract::query PHP Method

query() public method

All bind parameter names must begin with ':'
public query ( string | Zend_Db_Select $sql, array $bind = [] ) : Zend_Db_Statement_Pdo
$sql string | Zend_Db_Select The SQL statement with placeholders.
$bind array An array of data to bind to the placeholders.
return Zend_Db_Statement_Pdo
    public function query($sql, $bind = array())
    {
        if (empty($bind) && $sql instanceof Zend_Db_Select) {
            $bind = $sql->getBind();
        }
        if (is_array($bind)) {
            foreach ($bind as $name => $value) {
                if (!is_int($name) && !preg_match('/^:/', $name)) {
                    $newName = ":{$name}";
                    unset($bind[$name]);
                    $bind[$newName] = $value;
                }
            }
        }
        try {
            return parent::query($sql, $bind);
        } catch (PDOException $e) {
            /**
             * @see Zend_Db_Statement_Exception
             */
            require_once 'Zend/Db/Statement/Exception.php';
            throw new Zend_Db_Statement_Exception($e->getMessage(), $e->getCode(), $e);
        }
    }

Usage Example

Exemplo n.º 1
0
 function testFieldNamesAreLowercase()
 {
     $result = $this->_db->query('SELECT * FROM ' . self::TableName . ' WHERE date_created > :placeholder', array('placeholder' => '2006-01-01'));
     // use the PDOStatement $result to fetch all rows as an array
     $row = $result->fetch();
     $this->assertEquals(5, count($row));
     // correct number of fields
     $this->assertEquals('1', $row['id']);
     // correct data
     $this->assertTrue(array_key_exists('subtitle', $row));
     // "subTitle" is now "subtitle"
     $this->assertFalse(array_key_exists('subTitle', $row));
     // "subTitle" is not a key
 }
All Usage Examples Of Zend_Db_Adapter_Pdo_Abstract::query