Download the PHP package castroitalo/echoquery without Composer
On this page you can find all versions of the php package castroitalo/echoquery. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download castroitalo/echoquery
More information about castroitalo/echoquery
Files in castroitalo/echoquery
Package echoquery
Short Description EchoQuery facilitates the writing of SQL queries inside the PHP code
License MIT
Informations about the package echoquery
EchoQuery
EchoQuery offers a streamlined, intuitive interface for developers. It simplifies complex SQL scripting, enhances readability, and accelerates development, making database interactions effortless and efficient for projects of any scale.
Basic Usage
To be able to use the EchoQuery package you need to install it with the following command:
To generate a string with your query using EchoQuery just use the methods available:
-
Query example:
- PHP code with EchoQuery example:
Features
Select and From Statement
The base of any SQL query is the SELECT and FROM statement, you can easily do it with echo query:
Let's create this SQL code into PHP using EchoQuery:
Let's make it more simple:
In this case, every array passed in select method, is a column and its alias, you can pass as much columns as you want:
Where statement
You create each WHERE condition at time, if you want to take the column_one
data only the data that is greater than 10 you just do:
You can use ->where()
method with:
-
Comparison operators:
->equalsTo(mixed $value): Builder
->notEqualsTo(mixed $value, string $notEqualsToOperator = '!='): Builder
->lessThan(mixed $value): Builder
->lessThanEqualsTo(mixed $value): Builder
->greaterThan(mixed $value): Builder
->greaterThanEqualsTo(mixed $value): Builder
-
Logical operators:
->and(string $columnName): Builder
->or(string $columnName): Builder
->not(string $columnName): Builder
-
Pattern matching:
->like(string $pattern): Builder
->notLike(string $pattern): Builder
-
Range conditions:
->between(mixed $start, mixed $end): Builder
->notBetween(mixed $start, mixed $end): Builder
-
List conditions:
->in(array $list): Builder
->notIn(array $list): Builder
- Null conditions:
->isNull(): Builder
->isNotNull(): Builder
JOINS
To use joins you need to call the JOIN method you want, and specify the table and the JOIN columns like in:
To use JOIN with sub query you just need to use the equivalent sub query JOIN method:
-
INNER JOIN:
->innerJoin(array ...$joinInfo): Builder
->innerJoinSub(array ...$joinInfo): Builder
-
LEFT JOIN:
->leftJoin(array ...$joinInfo): Builder
->leftJoinSub(array ...$joinInfo): Builder
-
RIGHT JOIN:
->rightJoin(array ...$joinInfo): Builder
->rightJoinSub(array ...$joinInfo): Builder
-
FULL JOIN:
->fullJoin(array ...$joinInfo): Builder
->fullJoinSub(array ...$joinInfo): Builder
-
CROSS JOIN:
->crossJoin(array ...$joinInfo): Builder
->crossJoinSub(array ...$joinInfo): Builder
-
SELF JOIN:
->selfJoin(array ...$joinInfo): Builder
->selfJoinSub(array ...$joinInfo): Builder
- NATURAL JOIN:
->naturalJoin(array ...$joinInfo): Builder
->naturalJoinSub(array ...$joinInfo): Builder
UNIONS
To use use UNIONS just use the ->union(string $unionQuery): Builder
or ->unionAll(string $unionQuery): Builder
with the subsequent query as the parameter:
GROUP BY
To use GROUP BY on aggregate functions simply use the ->groupBy(string ...$columns): Builder
method, passing one or more columns to group:
ORDER BY
To use ORDER BY on columns simply use the ->orderBy(array ...$columns): Builder
method, passing one or more columns with the respective ordering function.
HAVING
For using HAVING just use the ->having(string $having): Builder
with one of the comparison operator:
Pagination
To create a pagination just use the ->pagination(int $limit, ?int $offset = null): Builder
method, passing the limit and an optional offset for it:
Contributing
To contribute to the project make sure you have read CONTRIBUTING section.
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CODE_OF_CONDUCT for details.
Credits
License
The MIT License (MIT). Please see License File for more information.