Every SQL can be split into multiple expressions. Each expression contains three parts:
Inheritance: extends Base
Ejemplo n.º 1
0
 public function query($sql, $values = array())
 {
     $sql = new Expressions($sql);
     $sql->set_connection($this);
     $sql->bind_values($values);
     $sql = trim($sql->to_s());
     $values = $values ? array_flatten($values) : array();
     if (!($sth = mysqli_prepare($this->connection, $sql))) {
         throw new DatabaseException(mysqli_error($this->connection), mysqli_errno($this->connection));
     }
     if (count($values) > 0) {
         $params = array($sth, '');
         foreach ($values as &$value) {
             if (is_int($value)) {
                 $params[1] .= 'i';
             } elseif (is_float($value)) {
                 $params[1] .= 'd';
             } else {
                 $params[1] .= 's';
             }
             $params[] =& $value;
         }
         if ($params[1]) {
             call_user_func_array('mysqli_stmt_bind_param', $params);
         }
     }
     if (is_int($ret = mysqli_stmt_execute($sth))) {
         return $ret;
     }
     return new MysqliResultSet($sth);
 }
Ejemplo n.º 2
0
 public function query($sql, $values = array())
 {
     if (getenv('LOG') == 'true') {
         $GLOBALS['logger']->log($sql, PEAR_LOG_INFO);
     }
     $sql = new Expressions($sql);
     $sql->set_connection($this);
     $sql->bind_values($values);
     $sql = trim($sql->to_s());
     $values = $values ? array_flatten($values) : array();
     if (!($sth = @$this->connection->prepare($sql))) {
         throw new DatabaseException($this->connection->lastErrorMsg(), $this->connection->lastErrorCode());
     }
     for ($i = 0, $n = count($values); $i < $n; ++$i) {
         if (is_string($values[$i])) {
             $type = SQLITE3_TEXT;
         } elseif (is_float($values[$i])) {
             $type = SQLITE3_FLOAT;
         } elseif (is_numeric($values[$i])) {
             $type = SQLITE3_INTEGER;
         } elseif (is_null($values[$i])) {
             $type = SQLITE3_NULL;
         } else {
             $type = SQLITE3_TEXT;
         }
         $sth->bindParam($i + 1, $values[$i], $type);
     }
     return $sth->execute();
 }
Ejemplo n.º 3
0
 private function build_insert()
 {
     require_once 'Expressions.php';
     $keys = join(',', $this->quoted_key_names());
     if ($this->sequence) {
         $sql = "INSERT INTO {$this->table}({$keys}," . $this->connection->quote_name($this->sequence[0]) . ") VALUES(?," . $this->connection->next_sequence_value($this->sequence[1]) . ")";
     } else {
         $sql = "INSERT INTO {$this->table}({$keys}) VALUES(?)";
     }
     $e = new Expressions($this->connection, $sql, array_values($this->data));
     return $e->to_s();
 }
Ejemplo n.º 4
0
 private function build_insert()
 {
     require_once 'Expressions.php';
     $keys = join(',', $this->quoted_key_names());
     $e = new Expressions($this->connection, "INSERT INTO {$this->table}({$keys}) VALUES(?)", array_values($this->data));
     return $e->to_s();
 }
Ejemplo n.º 5
0
 private function build_insert()
 {
     $keys = join(',', array_keys($this->data));
     $e = new Expressions("INSERT INTO {$this->table}({$keys}) VALUES(?)", array_values($this->data));
     $e->set_connection($this->connection);
     return $e->to_s();
 }