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
コード例 #1
0
ファイル: Common.php プロジェクト: jorgenils/zend-framework
 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
 }
コード例 #2
0
ファイル: DbTool.php プロジェクト: xert/icingaweb2
 /**
  * Execute a SQL statement and return the result
  *
  * Use $params to use a prepared statement.
  *
  * @param   string  $statement  The statement to execute
  * @param   array   $params     The params to bind
  *
  * @return  mixed
  */
 public function query($statement, $params = array())
 {
     if ($this->zendConn !== null) {
         return $this->zendConn->query($statement, $params);
     }
     if (empty($params)) {
         return $this->pdoConn->query($statement);
     }
     $stmt = $this->pdoConn->prepare($statement);
     $stmt->execute($params);
     return $stmt;
 }