예제 #1
0
파일: Statement.php 프로젝트: nkt/flame
 /**
  * @param array $parameters
  *
  * @return static
  * @throws Exception
  */
 public function execute($parameters = null)
 {
     if ($parameters !== null) {
         $parameters = array_intersect_key($parameters, $this->types);
         foreach ($this->placeholders as $i => $name) {
             $value =& $parameters[$name];
             if ($value === null) {
                 $this->bindValue($i + 1, null, Connection::PARAM_NULL);
             } else {
                 $type =& $this->types[$name];
                 if ($type === Connection::PARAM_INT) {
                     $value = (int) $value;
                 } elseif ($type === Connection::PARAM_DATE_TIME) {
                     $value = $this->grammar->buildDateTime($value);
                     $type = Connection::PARAM_STR;
                 } elseif ($type === Connection::PARAM_TIME) {
                     $value = $this->grammar->buildTime($value);
                     $type = Connection::PARAM_STR;
                 }
                 $this->bindValue($i + 1, $value, $type);
             }
         }
     }
     parent::execute();
     return $this;
 }
예제 #2
0
파일: GrammarTest.php 프로젝트: nkt/flame
 public function testBuildTime()
 {
     $date = new \DateTime();
     $expected = $date->format(Grammar::TIME_FORMAT);
     $this->assertEquals($expected, $this->grammar->buildTime($date));
     $this->assertEquals($expected, $this->grammar->buildTime($date->getTimestamp()));
     $this->assertEquals($expected, $this->grammar->buildTime($expected));
     $this->setExpectedException('InvalidArgumentException');
     $this->grammar->buildTime([]);
 }