Download the PHP package basephp/database without Composer
On this page you can find all versions of the php package basephp/database. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package database
Note: This repository requires the use of the BasePHP framework. If you would like to learn more about the framework, visit BasePHP.
BasePHP Component - Database
Database and Query Builder for BasePHP.
Quick Links:
- BasePHP Framework
- Example Application
- BasePHP Component - Database
Installation
(1) Add sensitive information in your .env
file
(2) If you do not have the /config/db.php
, then copy the db.example.php
from this repo and rename it.
Examples
Results:
Update items:
Insert items:
Delete items:
RAW SQL:
Query Builder
These methods are stackable
Method | Option | Description |
---|---|---|
table() |
Required - MUST BE FIRST | FROM table |
join() |
Optional | JOIN table |
select() |
Optional - Default: * |
SELECT fields |
where() |
Optional | WHERE |
in() |
Optional | IN (values) |
not() |
Optional | NOT IN (values) |
limit() |
Optional | LIMIT number |
offset() |
Optional | LIMIT offset,limit |
order() |
Optional | ORDER BY fields |
group() |
Optional | GROUP BY fields |
having() |
Optional | HAVING |
distinct() |
Optional | SELECT DISTINCT |
Note: For every new query, first use the table()
method.
Execute Queries
These methods execute "read" queries and return database results
Method | Description |
---|---|
get() |
Run the query and return all items as a Collection object |
first() |
Run the query and return the first item |
last() |
Run the query and return the last item |
count() |
Run a COUNT query and return the number |
sum('field') |
Get the SUM(field) of a table and return the number |
avg('field') |
Get the AVG(field) of a table and return the number |
min('field') |
Get the MIN(field) of a table and return the number |
max('field') |
Get the MAX(field) of a table and return the number |
These methods execute "write" queries
Method | Description |
---|---|
update(array) |
Run the UPDATE query |
insert(array) |
Run the INSERT query, returns insert id |
delete() |
Run the DELETE query |
increment(field, value) |
Run the UPDATE query |
decrement(field, value) |
Run the UPDATE query |
truncate() |
Run the TRUNCATE query |
Write a raw query
Method | Description |
---|---|
query(string) |
Write a raw SQL query and return its results |
Note: Raw Queries will return results into a Collection
, unless you are "writing" to the database.
Note: Queries that use INSERT
will return the insert_id
automatically
Utility Methods:
Method | Description |
---|---|
escape(string) |
Escape a string for database injection |
isWriteSql(string) |
Checks a string if the SQL statement is write type |
isInsertSql(string) |
Checks a string if the SQL statement is INSERT |
Note: all values passed into query methods (not custom SQL's) automatically run through escape()
Database Support
Currently only supports MySQL connections