Download the PHP package aberdeener/koss without Composer
On this page you can find all versions of the php package aberdeener/koss. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download aberdeener/koss
More information about aberdeener/koss
Files in aberdeener/koss
Package koss
Short Description Write MySQL queries in PHP faster and easier than ever before.
License MIT
Informations about the package koss
Roadmap
- Make chained join clauses more fluent, after
on()
add athen($callback)
(instead of current behaviour of multiple seperate calls and usage ofthrough($table)
) ? - Add
prefix(string $prefix)
function to set a table prefix to automatically append.
Documentation
- Requires PHP 8.0
Setup:
- Autoload Koss using Composer.
- Initiate a new Koss instance by passing your MySQL login and database information.
- Parameters:
- 1: Hostname
- 2: Port
- 3: Database name
- 4: Username
- 5: Password
Note: Your order of functions does not matter. You can limit()
and then choose to select more columns via columns()
after.
Core Functions:
Functions which are available in both Selection and Update/Insert queries.
execute()
- Execute compiled Koss MySQL code and output results
- Note: Without calling this function at the end of your code, nothing will output!
when(Closure | bool $expression, Closure $callback)
- Only execute
$callback
function when$expression
is true. - Note:
$expression
can be either a boolean value (5 < 10
) or an anonymous function which returns a boolean value
- Only execute
unless(Closure | bool $expression, Closure $callback)
- Only execute
$callback
function when$expression
is false. - Note:
$expression
can be either a boolean value or an anonymous function which returns a boolean value
- Only execute
where(string $column, string $operator, string $matches)
- Select rows in
$table
(must be previously provided via a select statement) with values in$column
that are$operator
to$match
- Note: If
$operator
is not provided,'='
will be assumed - Example SQL code:
WHERE username <> 'Aberdeener'
- Select rows in
like(string $column, string $like)
- Select rows in
$table
(must be previously provided via a select statement) with values in$column
that are similar to to$like
. - You must provide the
%
where you want them to be, Koss cannot assume anything. - Note: Multiple
like
andwhere
clauses can be passed and Koss will handle compiling the correct MySQL code - Example SQL code:
WHERE first_name LIKE %Tadhg%
- Select rows in
Selection Functions:
getAll(string $table)
- Select all columns in
$table
- Example SQL code:
SELECT * FROM users
- Select all columns in
getSome(string $table, array | string $columns)
- Select specific
$columns
(or just one column if a string is provided) in$table
- Example SQL code:
SELECT username, first_name, last_name FROM users
- Select specific
groupBy(string $column)
- Group together rows with same
$column
values - Example SQL code:
GROUP BY age
- Group together rows with same
orderBy(string $column, string $order)
- Sort output by
$column
eitherASC
orDESC
- Example SQL code:
ORDER BY first_name DESC
- Sort output by
limit(int $limit)
- Only return
$limit
rows. - Example SQL code:
LIMIT 3
- Only return
columns(array $columns)
- Also select
$columns
as well as whatever was passed in the originalgetSome()
column(string $column)
allows for selecting a single column.- Example SQL code:
SELECT username, first_name
- Also select
cast(string $column, string $type)
- Cast a specific
$column
's data to$type
when it is retreived from the database.
- Cast a specific
casts(array $casts)
- Cast multiple columns at the same time in SelectQuery.
$casts
must be an array in the format:
Update/Insert Functions:
-
update(string $table, array $values)
- Updates any rows in the
$table
to new$values
. -
$values
must be an array in the format:- Example SQL code:
UPDATE users SET username = 'Aberdeener' WHERE ...
- Example SQL code:
- Updates any rows in the
-
insert(string $table, array $row)
- Inserts a new row into
$table
. -
$row
must be an array in the format: - Example SQL code:
INSERT INTO users (username, first_name, last_name) VALUES ('Aberdeener', 'Tadhg', 'Boyle')
- Inserts a new row into
-
onDuplicateKey(array $values)
- Upon an insertion, if there is a unique column and it is overridden, run this code instead.
-
$values
must be an array in the format: - Example SQL code:
ON DUPLICATE KEY UPDATE username = 'Aber'
Other Functions:
Functions which are not in Selection or Update/Insert queries
execute(string $query)
- Execute provided
$query
and output results. - Common usage would be raw queries where Koss does not have functionality to help.
- Note: Cannot be mixed with other functions
- Execute provided
Examples
All assuming you have autoloaded Koss.php
and created a new instance of it with your database credentials.
-
Selecting information
-
Inserting information
- Updating information