PHP 클래스 db, kirby

파일 보기 프로젝트 열기: bastianallgeier/kirby 1 사용 예제들

공개 프로퍼티들

프로퍼티 타입 설명
$trace array Traces all db queries

공개 메소드들

메소드 설명
affected ( ) : integer Returns the number of affected rows for the last query
charset ( string $charset = 'utf8' ) : mixed Sets the charset for all queries The default and recommended charset is utf8
column ( string $table, string $column, mixed $where = null, string $order = null, integer $page = null, integer $limit = null ) : mixed Returns all values from single column of a table
connect ( ) : mixed The core connection method Tries to connect to the server Selects the database and sets the charset
connection ( ) : mixed Returns the current connection or false
count ( string $table, mixed $where = '' ) : integer Counts a number of rows in a table
database ( string $database ) : mixed Selects a database
delete ( string $table, mixed $where = '' ) : mixed Runs a DELETE query
disconnect ( ) : boolean Disconnects from the server
error ( string $msg = null, boolean $exit = false ) : mixed An internal error handler
escape ( string $value ) : string Escapes unwanted stuff in values like slashes, etc.
execute ( string $sql ) : mixed Executes a MySQL query without result set.
fetch ( resource $result, const $type = MYSQL_ASSOC ) : array Shortcut for mysql_fetch_array
field ( string $table, string $field, mixed $where = null, string $order = null ) : mixed Returns a single field value from a table
fields ( string $table ) : array Returns an array of fields in a given table
in ( array $array ) : string A simplifier to build IN clauses
insert ( string $table, mixed $input, boolean $ignore = false ) : mixed Runs a INSERT query
insert_all ( string $table, array $fields, array $values ) : mixed Runs a INSERT query with values
join ( string $table_1, string $table_2, string $on, mixed $select, mixed $where = null, string $order = null, integer $page = null, integer $limit = null, string $type = "JOIN" ) : mixed Joins two tables and returns data from them
last_id ( ) : integer Returns the last returned insert id
left_join ( string $table_1, string $table_2, string $on, mixed $select, mixed $where = null, string $order = null, integer $page = null, integer $limit = null ) : mixed Runs a LEFT JOIN
max ( string $table, string $column, mixed $where = null ) : mixed Gets the maximum value in a column of a table
min ( string $table, string $column, mixed $where = null ) : mixed Gets the minimum value in a column of a table
prefix ( string $table ) : string Adds a prefix to a table name if set in c::set('db.prefix', 'myprefix_'); This makes it possible to use table names in all methods without prefix and it will still be applied automatically.
query ( string $sql, boolean $fetch = true ) : mixed Runs a MySQL query.
replace ( string $table, mixed $input ) : mixed Runs a REPLACE query
row ( string $table, mixed $select = '*', mixed $where = null, string $order = null ) : mixed Returns a single row from a table
search_clause ( string $search, array $fields, string $mode = 'OR' ) : string A simplifier to build search clauses
select ( string $table, mixed $select = '*', mixed $where = null, string $order = null, integer $page = null, integer $limit = null, boolean $fetch = true ) : mixed Returns multiple rows from a table
select_clause ( $fields ) : string Builds a select clause from a simple array
simple_fields ( array $array ) : array Strips table specific column prefixes from the result array
sum ( string $table, string $column, mixed $where = null ) : mixed Gets the sum of values in a column of a table
update ( string $table, mixed $input, mixed $where ) : mixed Runs an UPDATE query
values ( array $input ) : string Makes it possible to use arrays for inputs instead of MySQL strings
where ( array $array, string $method = 'AND' ) : string A handler to convert key/value arrays to an where clause
with ( string $field, string $char ) : string An easy method to build a part of the where clause to find stuff by its first character

메소드 상세

affected() 정적인 공개 메소드

Returns the number of affected rows for the last query
static public affected ( ) : integer
리턴 integer

charset() 정적인 공개 메소드

Sets the charset for all queries The default and recommended charset is utf8
static public charset ( string $charset = 'utf8' ) : mixed
$charset string
리턴 mixed

column() 정적인 공개 메소드

Returns all values from single column of a table
static public column ( string $table, string $column, mixed $where = null, string $order = null, integer $page = null, integer $limit = null ) : mixed
$table string The table name
$column string The name of the column
$where mixed Either a key/value array as AND connected where clause or a simple MySQL where clause string
$order string Order clause without the order keyword. ie: "added desc"
$page integer a page number
$limit integer a number for rows to return
리턴 mixed

connect() 정적인 공개 메소드

It will only connect once and return that same connection for all following queries
static public connect ( ) : mixed
리턴 mixed

connection() 정적인 공개 메소드

Returns the current connection or false
static public connection ( ) : mixed
리턴 mixed

count() 정적인 공개 메소드

Counts a number of rows in a table
static public count ( string $table, mixed $where = '' ) : integer
$table string The table name
$where mixed Either a key/value array as AND connected where clause or a simple MySQL where clause string
리턴 integer

database() 정적인 공개 메소드

Selects a database
static public database ( string $database ) : mixed
$database string
리턴 mixed

delete() 정적인 공개 메소드

Runs a DELETE query
static public delete ( string $table, mixed $where = '' ) : mixed
$table string The table name
$where mixed Either a key/value array as AND connected where clause or a simple MySQL where clause string
리턴 mixed The number of affected rows or an error response

disconnect() 정적인 공개 메소드

Disconnects from the server
static public disconnect ( ) : boolean
리턴 boolean

error() 정적인 공개 메소드

An internal error handler
static public error ( string $msg = null, boolean $exit = false ) : mixed
$msg string The error/success message to return
$exit boolean die after this error?
리턴 mixed

escape() 정적인 공개 메소드

Escapes unwanted stuff in values like slashes, etc.
static public escape ( string $value ) : string
$value string
리턴 string Returns the escaped string

execute() 정적인 공개 메소드

This is used for queries like update, delete or insert
static public execute ( string $sql ) : mixed
$sql string The sql query
리턴 mixed

fetch() 정적인 공개 메소드

Shortcut for mysql_fetch_array
static public fetch ( resource $result, const $type = MYSQL_ASSOC ) : array
$result resource the unfetched result from db::query()
$type const PHP flag for mysql_fetch_array
리턴 array The key/value result array

field() 정적인 공개 메소드

Returns a single field value from a table
static public field ( string $table, string $field, mixed $where = null, string $order = null ) : mixed
$table string The table name
$field string The name of the field
$where mixed Either a key/value array as AND connected where clause or a simple MySQL where clause string
$order string Order clause without the order keyword. ie: "added desc"
리턴 mixed

fields() 정적인 공개 메소드

Returns an array of fields in a given table
static public fields ( string $table ) : array
$table string The table name
리턴 array The array of field names

in() 정적인 공개 메소드

A simplifier to build IN clauses
static public in ( array $array ) : string
$array array An array of fieldnames
리턴 string The MySQL string for the where clause

insert() 정적인 공개 메소드

Runs a INSERT query
static public insert ( string $table, mixed $input, boolean $ignore = false ) : mixed
$table string The table name
$input mixed Either a key/value array or a valid MySQL insert string
$ignore boolean Set this to true to ignore duplicates
리턴 mixed The last inserted id if everything went fine or an error response.

insert_all() 정적인 공개 메소드

Runs a INSERT query with values
static public insert_all ( string $table, array $fields, array $values ) : mixed
$table string The table name
$fields array an array of field names
$values array an array of array of keys and values.
리턴 mixed The last inserted id if everything went fine or an error response.

join() 정적인 공개 메소드

Joins two tables and returns data from them
static public join ( string $table_1, string $table_2, string $on, mixed $select, mixed $where = null, string $order = null, integer $page = null, integer $limit = null, string $type = "JOIN" ) : mixed
$table_1 string The table name of the first table
$table_2 string The table name of the second table
$on string The MySQL ON clause without the ON keyword. ie: "user_id = comment_user"
$select mixed Either an array of fields or a MySQL string of fields
$where mixed Either a key/value array as AND connected where clause or a simple MySQL where clause string
$order string Order clause without the order keyword. ie: "added desc"
$page integer a page number
$limit integer a number for rows to return
$type string The join type (JOIN, LEFT, RIGHT, INNER)
리턴 mixed

last_id() 정적인 공개 메소드

Returns the last returned insert id
static public last_id ( ) : integer
리턴 integer

left_join() 정적인 공개 메소드

Runs a LEFT JOIN
static public left_join ( string $table_1, string $table_2, string $on, mixed $select, mixed $where = null, string $order = null, integer $page = null, integer $limit = null ) : mixed
$table_1 string The table name of the first table
$table_2 string The table name of the second table
$on string The MySQL ON clause without the ON keyword. ie: "user_id = comment_user"
$select mixed Either an array of fields or a MySQL string of fields
$where mixed Either a key/value array as AND connected where clause or a simple MySQL where clause string
$order string Order clause without the order keyword. ie: "added desc"
$page integer a page number
$limit integer a number for rows to return
리턴 mixed

max() 정적인 공개 메소드

Gets the maximum value in a column of a table
static public max ( string $table, string $column, mixed $where = null ) : mixed
$table string The table name
$column string The name of the column
$where mixed Either a key/value array as AND connected where clause or a simple MySQL where clause string
리턴 mixed

min() 정적인 공개 메소드

Gets the minimum value in a column of a table
static public min ( string $table, string $column, mixed $where = null ) : mixed
$table string The table name
$column string The name of the column
$where mixed Either a key/value array as AND connected where clause or a simple MySQL where clause string
리턴 mixed

prefix() 정적인 공개 메소드

Adds a prefix to a table name if set in c::set('db.prefix', 'myprefix_'); This makes it possible to use table names in all methods without prefix and it will still be applied automatically.
static public prefix ( string $table ) : string
$table string The name of the table with or without prefix
리턴 string The sanitized table name.

query() 정적인 공개 메소드

You can use any valid MySQL query here. This is also the fallback method if you can't use one of the provided shortcut methods from this class.
static public query ( string $sql, boolean $fetch = true ) : mixed
$sql string The sql query
$fetch boolean True: apply db::fetch to the result, false: go without db::fetch
리턴 mixed

replace() 정적인 공개 메소드

Runs a REPLACE query
static public replace ( string $table, mixed $input ) : mixed
$table string The table name
$input mixed Either a key/value array or a valid MySQL insert string
리턴 mixed The last inserted id if everything went fine or an error response.

row() 정적인 공개 메소드

Returns a single row from a table
static public row ( string $table, mixed $select = '*', mixed $where = null, string $order = null ) : mixed
$table string The table name
$select mixed Either an array of fields or a MySQL string of fields
$where mixed Either a key/value array as AND connected where clause or a simple MySQL where clause string
$order string Order clause without the order keyword. ie: "added desc"
리턴 mixed

search_clause() 정적인 공개 메소드

A simplifier to build search clauses
static public search_clause ( string $search, array $fields, string $mode = 'OR' ) : string
$search string The search word
$fields array An array of fields to search
$mode string OR or AND
리턴 string Returns the final where clause

select() 정적인 공개 메소드

Returns multiple rows from a table
static public select ( string $table, mixed $select = '*', mixed $where = null, string $order = null, integer $page = null, integer $limit = null, boolean $fetch = true ) : mixed
$table string The table name
$select mixed Either an array of fields or a MySQL string of fields
$where mixed Either a key/value array as AND connected where clause or a simple MySQL where clause string
$order string Order clause without the order keyword. ie: "added desc"
$page integer a page number
$limit integer a number for rows to return
$fetch boolean true: apply db::fetch(), false: don't apply db::fetch()
리턴 mixed

select_clause() 정적인 공개 메소드

Builds a select clause from a simple array
static public select_clause ( $fields ) : string
리턴 string The MySQL string

simple_fields() 정적인 공개 메소드

If you use column names like user_username, user_id, etc. use this method on the result array to strip user_ of all fields
static public simple_fields ( array $array ) : array
$array array The result array
리턴 array The result array without those damn prefixes.

sum() 정적인 공개 메소드

Gets the sum of values in a column of a table
static public sum ( string $table, string $column, mixed $where = null ) : mixed
$table string The table name
$column string The name of the column
$where mixed Either a key/value array as AND connected where clause or a simple MySQL where clause string
리턴 mixed

update() 정적인 공개 메소드

Runs an UPDATE query
static public update ( string $table, mixed $input, mixed $where ) : mixed
$table string The table name
$input mixed Either a key/value array or a valid MySQL insert string
$where mixed Either a key/value array as AND connected where clause or a simple MySQL where clause string
리턴 mixed The number of affected rows or an error response

values() 정적인 공개 메소드

Makes it possible to use arrays for inputs instead of MySQL strings
static public values ( array $input ) : string
$input array
리턴 string The final MySQL string, which will be used in the queries.

where() 정적인 공개 메소드

A handler to convert key/value arrays to an where clause
static public where ( array $array, string $method = 'AND' ) : string
$array array keys/values for the where clause
$method string AND or OR
리턴 string The MySQL string for the where clause

with() 정적인 공개 메소드

An easy method to build a part of the where clause to find stuff by its first character
static public with ( string $field, string $char ) : string
$field string The name of the field
$char string The character to search for
리턴 string Returns the where clause part

프로퍼티 상세

$trace 공개적으로 정적으로 프로퍼티

Traces all db queries
public static array $trace
리턴 array