示例#1
0
 public function testPrepare()
 {
     $val = QueryBuilder::prepare(" 'MyName' is hello ");
     $expectedVal = "'`MyName` is hello'";
     $this->assertEquals($expectedVal, $val);
     $val2 = QueryBuilder::prepare(['hello']);
     $expectedVal2 = "'hello'";
     $this->assertEquals($expectedVal2, $val2);
     $val3 = QueryBuilder::prepare(1);
     $expectedVal3 = "'1'";
     $this->assertEquals($expectedVal3, $val3);
     $val = QueryBuilder::prepare(0);
     $expectedVal = "0";
     $this->assertEquals($expectedVal, $val);
     $val = QueryBuilder::prepare('0');
     $expectedVal = "0";
     $this->assertEquals($expectedVal, $val);
     $val = QueryBuilder::prepare('');
     $expectedVal = '""';
     $this->assertEquals($expectedVal, $val);
     $val = QueryBuilder::prepare(NULL);
     $expectedVal = 'NULL';
     $this->assertEquals($expectedVal, $val);
     $val = QueryBuilder::prepare(false);
     $expectedVal = 0;
     $this->assertEquals($expectedVal, $val);
     $val = QueryBuilder::prepare(true);
     $expectedVal = "'1'";
     $this->assertEquals($expectedVal, $val);
 }
示例#2
0
 /**
  * @param string $sql
  * @param array $params
  * @return PDOStatement
  */
 private function execute($sql, $params = array())
 {
     if ($this->testing) {
         return NULL;
     }
     $this->debug($sql);
     if ($this->fictive) {
         if (QueryBuilder::queryIsChangingData($sql)) {
             return NULL;
         }
     }
     try {
         $sth = $this->connection->prepare($sql);
         $sth->execute($params);
     } catch (PDOException $e) {
         $this->logExecutionError($sql, $e);
         return NULL;
     }
     return $sth;
 }