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); }
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(); }
private function apply_where_conditions($args) { require_once 'Expressions.php'; $num_args = count($args); if ($num_args == 1 && is_hash($args[0])) { $hash = is_null($this->joins) ? $args[0] : $this->prepend_table_name_to_fields($args[0]); $e = new Expressions($this->connection, $hash); $this->where = $e->to_s(); $this->where_values = array_flatten($e->values()); } elseif ($num_args > 0) { // if the values has a nested array then we'll need to use Expressions to expand the bind marker for us $values = array_slice($args, 1); foreach ($values as $name => &$value) { if (is_array($value)) { $e = new Expressions($this->connection, $args[0]); $e->bind_values($values); $this->where = $e->to_s(); $this->where_values = array_flatten($e->values()); return; } } // no nested array so nothing special to do $this->where = $args[0]; $this->where_values =& $values; } }
private function apply_where_conditions($args) { $num_args = count($args); if ($num_args == 1 && is_hash($args[0])) { $e = new Expressions($args[0]); $e->set_connection($this->connection); $this->where = $e->to_s(); $this->where_values = array_flatten($e->values()); } elseif ($num_args > 0) { // if the values has a nested array then we'll need to use Expressions to expand the bind marker for us $values = array_slice($args, 1); foreach ($values as $name => &$value) { if (is_array($value)) { $e = new Expressions($args[0]); $e->set_connection($this->connection); $e->bind_values($values); $this->where = $e->to_s(); $this->where_values = array_flatten($e->values()); return; } } // no nested array so nothing special to do $this->where = $args[0]; $this->where_values =& $values; } }