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
$callbackfunction when$expressionis true. - Note:
$expressioncan 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
$callbackfunction when$expressionis false. - Note:
$expressioncan 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$columnthat are$operatorto$match - Note: If
$operatoris 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$columnthat are similar to to$like. - You must provide the
%where you want them to be, Koss cannot assume anything. - Note: Multiple
likeandwhereclauses 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
$columnvalues - Example SQL code:
GROUP BY age
- Group together rows with same
orderBy(string $column, string $order)- Sort output by
$columneitherASCorDESC - Example SQL code:
ORDER BY first_name DESC
- Sort output by
limit(int $limit)- Only return
$limitrows. - Example SQL code:
LIMIT 3
- Only return
columns(array $columns)- Also select
$columnsas 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$typewhen it is retreived from the database.
- Cast a specific
casts(array $casts)- Cast multiple columns at the same time in SelectQuery.
$castsmust be an array in the format:
Update/Insert Functions:
-
update(string $table, array $values)- Updates any rows in the
$tableto new$values. -
$valuesmust 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. -
$rowmust 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.
-
$valuesmust 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
$queryand 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