pecee / pixie
Lightweight, fast query-builder for PHP based on Laravel Eloquent but with less overhead.
Installs: 23 293
Dependents: 7
Suggesters: 1
Security: 0
Stars: 41
Watchers: 4
Forks: 13
Open Issues: 8
Requires
- php: >=7.1
- ext-pdo: *
Requires (Dev)
- ext-pdo_sqlite: *
- mockery/mockery: ^1
- phpstan/phpstan: ^0
- phpstan/phpstan-deprecation-rules: ^0
- phpstan/phpstan-phpunit: ^0
- phpstan/phpstan-strict-rules: ^0
- phpunit/phpunit: ^8.0
Suggests
- ext-pdo_sqlite: Add extension for SQLite support
- dev-v4-release
- 4.16.3
- 4.16.2
- 4.16.1
- 4.16.0
- 4.15.8
- 4.15.7
- 4.15.6
- 4.15.5
- 4.15.4
- 4.15.3
- 4.15.2
- 4.15.1
- 4.15.0
- 4.14.0
- 4.13.0
- 4.12.2
- 4.12.1
- 4.12.0
- 4.11.0
- 4.10.0
- 4.9.1
- 4.9.0
- 4.8.1
- 4.8.0
- 4.7.2
- 4.7.1
- 4.7.0
- 4.6.0
- 4.5.1
- 4.5.0
- 4.4.1
- 4.4.0
- 4.3.0
- 4.2.6
- 4.2.5
- 4.2.4
- 4.2.2
- 4.2.1
- 4.2.0
- 4.1.3
- 4.1.2
- 4.1.1
- 4.1.0
- 4.0.0
- 3.6.4
- 3.6.3
- 3.6.1
- 3.6.0
- 3.5.2
- 3.5.1
- 3.5.0
- 3.4.2
- 3.4.1
- 3.4.0
- 3.3.0
- 3.2.3
- 3.2.2
- 3.2.1
- 3.2.0
- 3.1.0
- 3.0.1
- 3.0.0
- dev-v4-development
- dev-feature-unique-select
- dev-v3-release
- dev-v3-development
- dev-v3-select-from-subquery
This package is auto-updated.
Last update: 2024-11-06 15:09:12 UTC
README
A lightweight, expressive, framework agnostic query builder for PHP it can also be referred as a Database Abstraction Layer. Pixie supports MySQL, MS-SQL, SQLite and PostgreSQL will handle all your query sanitization, table alias, unions among many other things, with a unified API.
The syntax is similar to Laravel's query builder "Eloquent", but with less overhead.
This library is stable, maintained and are used by sites around the world (check the credits).
Requirements:
- PHP version 7.1 or higher is required for pecee-pixie version 4.x and above (versions prior to 4.x are available here).
- PDO extension enabled.
Features:
- Improved sub-queries.
- Custom prefix/aliases for tables (prefix.
table
). - Support for not defining table and/or removing defined table.
- Better handling of
Raw
objects inwhere
statements. - Union queries.
- Better connection handling.
- Performance optimisations.
- Tons of bug fixes.
- Much more...
Including all the original features like:
- Query events
- Nested criteria
- Sub queries
- Nested queries
- Multiple database connections.
Most importantly this project is used on many live-sites and maintained.
Examples
// Make sure you have Composer's autoload file included require 'vendor/autoload.php'; // Create a connection, once only. $config = [ // Name of database driver or IConnectionAdapter class 'driver' => 'mysql', 'host' => 'localhost', 'database' => 'your-database', 'username' => 'root', 'password' => 'your-password', // Optional 'charset' => 'utf8', // Optional 'collation' => 'utf8_unicode_ci', // Table prefix, optional 'prefix' => 'cb_', // PDO constructor options, optional 'options' => [ PDO::ATTR_TIMEOUT => 5, PDO::ATTR_EMULATE_PREPARES => false, ], ]; $queryBuilder = (new \Pecee\Pixie\Connection('mysql', $config))->getQueryBuilder();
Simple query:
Get user with the id of 3
. Returns null
when no match.
$user = $queryBuilder ->table('users') ->find(3);
Full queries:
Get all users with blue or red hair.
$users = $queryBuilder ->table('users') ->where('hair_color', '=', 'blue') ->orWhere('hair_color', '=', 'red') ->get();
Table of Contents
- Installation
- Feedback and development
- Connecting to the database
- Select
- Where
- Group- and order by
- Having
- Limit and offset
- Join
- Unions
- Raw query
- Insert
- Update
- Delete
- Transactions
- Get raw query
- Sub-queries and nested queries
- Getting the PDO instance
- Fetch results as objects of specified class
- Advanced
- Query events
- Exceptions
- Credits
Installation
Pixie uses Composer to make things easy.
Learn to use composer and add this to require section (in your composer.json):
composer install pecee/pixie
Feedback and development
If you are missing a feature, experience problems or have ideas or feedback that you want us to hear, please feel free to create an issue.
Issues guidelines
-
Please be as detailed as possible in the description when creating a new issue. This will help others to more easily understand- and solve your issue. For example: if you are experiencing issues, you should provide the necessary steps to reproduce the error within your description.
-
We love to hear out any ideas or feedback to the library.
Contribution and development guidelines
-
Please try to follow the PSR-2 codestyle guidelines.
-
Please create your pull requests to the development base that matches the version number you want to change. For example when pushing changes to version 3, the pull request should use the
v3-development
base/branch. -
Create detailed descriptions for your commits, as these will be used in the changelog for new releases.
-
When changing existing functionality, please ensure that the unit-tests working.
-
When adding new stuff, please remember to add new unit-tests for the functionality.
Connecting to the database
Pixie supports three database drivers, MySQL, SQLite and PostgreSQL. You can specify the driver during connection and the associated configuration when creating a new connection. You can also create multiple connections, but you can use alias for only one connection at a time.;
// Make sure you have Composer's autoload file included require 'vendor/autoload.php'; $config = [ 'driver' => 'mysql', 'host' => 'localhost', 'database' => 'your-database', 'username' => 'root', 'password' => 'your-password', 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'prefix' => '', ]; // Creates new connection $connection = new \Pecee\Pixie\Connection('mysql', $config); // Get the query-builder object which will initialize the database connection $queryBuilder = $connection->getQueryBuilder(); // Run query $person = $queryBuilder ->table('persons') ->where('name', '=', 'Bobby') ->first();
$connection
here is optional, if not given it will always associate itself to the first connection, but it can be useful when you have multiple database connections.
NOTE:
Calling the getQueryBuilder
method will automatically make a connection to the database, if none has already established.
If you want to access the Pdo
instance directly from the Connection
class, make sure to call $connection->connect();
to establish a connection to the database.
SQLite and PostgreSQL config example
The example below is for use with sqlite-databases.
$queryBuilder = new \Pecee\Pixie\Connection('sqlite', [ 'driver' => 'sqlite', 'database' => 'your-file.sqlite', 'prefix' => 'cb_', ]);
The example below is for pgsql databases.
$queryBuilder = new \Pecee\Pixie\Connection('pgsql', [ 'driver' => 'pgsql', 'host' => 'localhost', 'database' => 'your-database', 'username' => 'postgres', 'password' => 'your-password', 'charset' => 'utf8', 'prefix' => 'cb_', 'schema' => 'public', ]);
Select
It is recommend to use table()
method before every query, except raw query()
.
To select from multiple tables just pass an array.
However this is not required.
$queryBuilder->table(array('mytable1', 'mytable2'));
Table alias
You can easily set the table alias by using
$queryBuilder ->table(['table1' => 'foo1']) ->join('table2', 'table2.person_id', '=', 'foo1.id');
You can change the alias anytime by using:
$queryBuilder->alias('foo1', 'table1'); // Simplified way... $queryBuilder->table('table1')->alias('foo1');
Output:
SELECT * FROM `table1` AS `foo1` INNER JOIN `cb_table2` ON `cb_table2`.`person_id` = `cb_foo1`.`id`
NOTE:
You can always remove a table from a query by calling the table
method with no arguments like this $queryBuilder->table()
.
Get easily
The query below returns the (first) row where id = 3, null if no rows.
$row = $queryBuilder ->table('my_table') ->find(3);
Access your row like, echo $row->name
. If your field name is not id
then pass the field name as second parameter $queryBuilder->table('my_table')->find(3, 'person_id');
.
The query below returns the all rows where name = 'Sana', null if no rows.
$result = $queryBuilder ->table('my_table') ->findAll('name', 'Sana');
Multiple selects
$queryBuilder ->select( [ 'mytable.myfield1', 'mytable.myfield2', 'another_table.myfield3' ] );
Using select method multiple times select('a')->select('b')
will also select a
and b
. Can be useful if you want to do conditional selects (within a PHP if
).
Select distinct
$queryBuilder->selectDistinct(array('mytable.myfield1', 'mytable.myfield2'));
Select from query
You can easily select items from another query by using
$subQuery = $queryBuilder->table('person'); $builder = $queryBuilder->table($queryBuilder->subQuery($subQuery))->where('id', '=', 2);
Will produce the following output:
SELECT * FROM (SELECT * FROM `person`) WHERE `id` = 2
Select single field
$queryBuilder->table('my_table')->select('*');
Select multiple fields
$queryBuilder->table('my_table')->select(array('field1', 'field2'));
Get all
Returns an array.
$results = $queryBuilder ->table('my_table') ->where('name', '=', 'Sana') ->get();
You can loop through it like:
foreach ($results as $row) { echo $row->name; }
Get first row
$row = $queryBuilder ->table('my_table') ->where('name', '=', 'Sana') ->first();
Returns the first row, or null if there is no record. Using this method you can also make sure if a record exists. Access these like echo $row->name
.
Aggregate methods
Getting the row count
This will return the count for the entire number of rows in the result.
The default behavior will count *
(all) fields. You can specify a custom field by changing the field
parameter.
$queryBuilder ->table('my_table') ->where('name', '=', 'Sana') ->count();
Getting the sum
This will return the sum for a field in the entire number of rows in the result.
$queryBuilder ->table('my_table') ->where('name', '=', 'Sana') ->sum('views');
Getting the average
This will return the average for a field in the entire number of rows in the result.
$queryBuilder ->table('my_table') ->where('name', '=', 'Sana') ->average('views');
Getting the minimum
This will return the minimum for a field in the entire number of rows in the result.
$queryBuilder ->table('my_table') ->where('name', '=', 'Sana') ->min('views');
Getting the maximum
This will return the average for a field in the entire number of rows in the result.
$queryBuilder ->table('my_table') ->where('name', '=', 'Sana') ->max('views');
Select with sub-queries
// Creates the first sub-query $subQuery1 = $queryBuilder ->table('mail') ->select( $queryBuilder->raw('COUNT(*)') ); // Create the second sub-query $subQuery2 = $queryBuilder ->table('event_message') ->select( $queryBuilder->raw('COUNT(*)') ); // Executes the query which uses the subqueries as fields $count = $queryBuilder ->select( $queryBuilder->subQuery($subQuery1, 'row1'), $queryBuilder->subQuery($subQuery2, 'row2') ) ->first();
The example above will output a SQL-query like this:
SELECT (SELECT COUNT(*) FROM `cb_mail`) AS row1, (SELECT COUNT(*) FROM `cb_event_message`) AS row2 LIMIT 1
You can also easily create a subjquery within the where
statement:
$queryBuilder->where($queryBuilder->subQuery($subQuery), '!=', 'value');
Where
Basic syntax is (fieldname, operator, value)
, if you give two parameters then =
operator is assumed. So where('name', 'usman')
and where('name', '=', 'usman')
is the same.
$queryBuilder ->table('my_table') ->where('name', '=', 'usman') ->whereNot('age', '>', 25) ->orWhere('type', '=', 'admin') ->orWhereNot('description', 'LIKE', '%query%');
Where in
$queryBuilder ->table('my_table') ->whereIn('name', array('usman', 'sana')) ->orWhereIn('name', array('heera', 'dalim')); $queryBuilder ->table('my_table') ->whereNotIn('name', array('heera', 'dalim')) ->orWhereNotIn('name', array('usman', 'sana'));
Where between
$queryBuilder ->table('my_table') ->whereBetween('id', 10, 100) ->orWhereBetween('status', 5, 8);
Where null
$queryBuilder ->table('my_table') ->whereNull('modified') ->orWhereNull('field2') ->whereNotNull('field3') ->orWhereNotNull('field4');
Grouped where
Sometimes queries get complex, where you need grouped criteria, for example WHERE age = 10 and (name like '%usman%' or description LIKE '%usman%')
.
Pixie allows you to do so, you can nest as many closures as you need, like below.
$queryBuilder ->table('my_table') ->where('my_table.age', 10) ->where(function(QueryBuilderHandler $qb) { $qb->where('name', 'LIKE', '%pecee%'); // You can provide a closure on these wheres too, to nest further. $qb->orWhere('description', 'LIKE', '%usman%'); });
Group- and order by
$query = $queryBuilder ->table('my_table') ->groupBy('age') ->orderBy('created_at', 'ASC');
Multiple group by
$queryBuilder ->groupBy(array('mytable.myfield1', 'mytable.myfield2', 'another_table.myfield3')); ->orderBy(array('mytable.myfield1', 'mytable.myfield2', 'another_table.myfield3'));
Using groupBy()
or orderBy()
methods multiple times groupBy('a')->groupBy('b')
will also group by first a
and than b
. Can be useful if you want to do conditional grouping (within a PHP if
). Same applies to orderBy()
.
Having
$queryBuilder ->having('total_count', '>', 2) ->orHaving('type', '=', 'admin');
Limit and offset
$queryBuilder ->limit(30); ->offset(10);
Join
$queryBuilder ->table('my_table') ->join('another_table', 'another_table.person_id', '=', 'my_table.id')
Available methods,
- join() or innerJoin
- leftJoin()
- rightJoin()
If you need FULL OUTER
join or any other join, just pass it as 5th parameter of join
method.
$queryBuilder ->join('another_table', 'another_table.person_id', '=', 'my_table.id', 'FULL OUTER')
Join USING syntax
The JOIN USING
syntax allows you to easily map two identical identifiers to one, which can be helpful on large queries.
Example:
$queryBuilder ->table('user') ->join('user_data', 'user_data.user_id', '=', 'user.user_id');
Can be simplified to:
$queryBuilder ->table('user') ->joinUsing('user_data', 'user_id');
Multiple join criteria
If you need more than one criterion to join a table then pass a closure as second parameter.
$queryBuilder ->join('another_table', function($table) { $table ->on('another_table.person_id', '=', 'my_table.id') ->on('another_table.person_id2', '=', 'my_table.id2') ->orOn('another_table.age', '>', $queryBuilder->raw(1)); })
Unions
You can easily create unions by calling the union
method on the QueryBuilderHandler
.
Example:
$firstQuery = $queryBuilder ->table('people') ->whereNull('email'); $secondQuery = $queryBuilder ->table('people') ->where('hair_color', '=', 'green') ->union($firstQuery); $thirdQuery = $queryBuilder ->table('people') ->where('gender', '=', 'male') ->union($secondQuery); $items = $thirdQuery->get();
The example above will create a sql-statement similar to this:
( SELECT * FROM `cb_people` WHERE `gender` = 'male' ) UNION ( SELECT * FROM `cb_people` WHERE `email` IS NULL ) UNION ( SELECT * FROM `cb_people` WHERE `hair_color` = 'green' )
Raw query
You can always perform raw queries, if needed.
$query = $queryBuilder->query('SELECT * FROM persons WHERE age = 12'); $kids = $query->get();
You can also pass custom bindings
$queryBuilder ->query('SELECT * FROM persons WHERE age = ? AND name = ?', array(10, 'usman'));
Raw expressions
When you wrap an expression with raw()
method, Pixie doesn't try to sanitize these.
$queryBuilder ->table('my_table') ->select($queryBuilder->raw('count(cb_my_table.id) as tot')) ->where('value', '=', 'Ifrah') ->where($queryBuilder->raw('DATE(?)', 'now'))
NOTE: Queries that run through query()
method are not sanitized until you pass all values through bindings. Queries that run through raw()
method are not sanitized either, you have to do it yourself. And of course these don't add table prefix too, but you can use the addTablePrefix()
method.
Insert
$data = [ 'name' => 'Sana', 'description' => 'Blah' ]; $insertId = $queryBuilder ->table('my_table') ->insert($data);
insert()
method returns the insert id.
Batch insert
$data = [ array( 'name' => 'Sana', 'description' => 'Blah' ), array( 'name' => 'Usman', 'description' => 'Blah' ), ]; $insertIds = $queryBuilder ->table('my_table') ->insert($data);
In case of batch insert, it will return an array of insert ids.
Insert with ON DUPLICATE KEY statement
$data = [ 'name' => 'Sana', 'counter' => 1 ]; $dataUpdate = [ 'name' => 'Sana', 'counter' => 2 ]; $insertId = $queryBuilder ->table('my_table') ->onDuplicateKeyUpdate($dataUpdate) ->insert($data);
Update
$data = [ 'name' => 'Sana', 'description' => 'Blah' ]; $queryBuilder ->table('my_table') ->where('id', 5) ->update($data);
Will update the name field to Sana and description field to Blah where id = 5.
Delete
$queryBuilder ->table('my_table') ->where('id', '>', 5) ->delete();
Will delete all the rows where id is greater than 5.
Transactions
Pixie has the ability to run database "transactions", in which all database changes are not saved until committed. That way, if something goes wrong or differently then you intend, the database changes are not saved and no changes are made.
Here's a basic transaction:
$queryBuilder ->transaction(function (Transaction $transaction) { $transaction ->table('my_table') ->insert(array( 'name' => 'Test', 'url' => 'example.com' ); $transaction ->table('my_table') ->insert(array( 'name' => 'Test2', 'url' => 'example.com' )); });
If this were to cause any errors (such as a duplicate name or some other such error), neither data set would show up in the database. If not, the changes would be successfully saved.
If you wish to manually commit or rollback your changes, you can use the
commit()
and rollback()
methods accordingly:
$queryBuilder ->transaction(function (Transaction $transaction) { $transaction ->table('my_table') ->insert($data); // Commit changes (data will be saved) $transaction->commit(); // Rollback changes (data would be rejected) $transaction->rollback(); } );
Transactions will automatically be used when inserting multiple records. For example:
$queryBuilder->table('people')->insert([ [ 'name' => 'Simon', 'age' => 12, 'awesome' => true, 'nickname' => 'ponylover94', ], [ 'name' => 'Peter', 'age' => 40, 'awesome' => false, 'nickname' => null, ], [ 'name' => 'Bobby', 'age' => 20, 'awesome' => true, 'nickname' => 'peter', ], ]);
Get raw query
Sometimes you may need to get the query string, it's possible.
$queryHandler = $queryBuilder ->table('my_table') ->where('id', '=', 3) ->getQuery();
getQuery()
will return a QueryBuilderHandler
object.
You can use this to get the SQL, bindings or raw SQL.
$queryHandler->getSql();
Calling getSql()
will return the SQL-query without any processing.
SELECT * FROM my_table where `id` = ?
You can easily get any bindings on the query by calling the getBindings()
method.
Example:
$queryHandler->getBindings();
You can also get the raw SQL-query directly by calling the getRawSql()
method.
Example:
$queryHandler->getRawSql();
Calling the getRawSql()
method will return a query including bindings like this.
SELECT * FROM my_table where `id` = 3
Get QueryObject from last executed query
You can also retrieve the query-object from the last executed query.
Example:
$queryString = $queryBuilder->getLastQuery()->getRawSql();
Sub-queries and nested queries
Rarely but you may need to do sub queries or nested queries. Pixie is powerful enough to do this for you. You can create different query objects and use the $queryBuilder->subQuery()
method.
$subQuery = $queryBuilder ->table('person_details') ->select('details') ->where('person_id', '=', 3); $query = $queryBuilder ->table('my_table') ->select('my_table.*') ->select( $queryBuilder->subQuery($subQuery, 'table_alias1') ); $nestedQuery = $queryBuilder ->table( $queryBuilder->subQuery($query, 'table_alias2') ) ->select('*'); // Execute query $result = $nestedQuery->get();
This will produce a query like this:
SELECT * FROM (SELECT `cb_my_table`.*, (SELECT `details` FROM `cb_person_details` WHERE `person_id` = 3) AS table_alias1 FROM `cb_my_table`) AS table_alias2
NOTE:
Pixie doesn't use bindings for sub queries and nested queries. It quotes values with PDO's quote()
method.
Getting the PDO instance
If you need the \PDO
instance, you can easily get it by calling:
$queryBuilder->pdo();
If you want to get the Connection
object you can do so like this:
$connection = $queryBuilder->getConnection();
Fetch results as objects of specified class
Simply call asObject
query's method.
$queryBuilder ->table('my_table') ->asObject('SomeClass', array('ctor', 'args')) ->first();
Furthermore, you may fine-tune fetching mode by calling setFetchMode
method.
$queryBuilder ->table('my_table') ->setFetchMode(PDO::FETCH_COLUMN|PDO::FETCH_UNIQUE) ->get();
Advanced
Enable query-overwriting
If enabled calling from, select etc. will overwrite any existing values from previous calls in query.
You can enable or disable query-overwriting by calling the setOverwriteEnabled
method on the QueryBuilderHandler
object.
The feature is disabled as default.
Example:
$queryBuilder ->setOverwriteEnabled(true);
If you want this feature to be enabled on all QueryBuilderHandler
object as default, you can add the following setting to the connection configuration:
$adapterConfig = [ 'query_overwriting' => false, ];
Query events
Pixie comes with powerful query events to supercharge your application. These events are like database triggers, you can perform some actions when an event occurs, for example you can hook after-delete
event of a table and delete related data from another table.
Available events
Registering event
You can easily register a new event either by using the registerEvent
method on either the QueryBuilderHandler
, Connection
or EventHandler
class.
The event needs a custom callback function with a EventArguments
object as parameters.
Examples:
$queryBuilder->registerEvent(EventHandler::EVENT_BEFORE_SELECT, function(EventArguments $arguments) { $arguments ->getQueryBuilder() ->where('status', '!=', 'banned'); }, 'users');
Now every time a select query occurs on users
table, it will add this where criteria, so banned users don't get access.
The syntax is registerEvent('event type', action in a closure, 'table name')
.
If you want the event to be performed when any table is being queried, provide ':any'
as table name.
Other examples:
After inserting data into my_table
, details will be inserted into another table
$queryBuilder->registerEvent(EventHandler::EVENT_AFTER_INSERT, function(EventArguments $arguments) { $arguments ->getQueryBuilder() ->table('person_details')->insert(array( 'person_id' => $insertId, 'details' => 'Meh', 'age' => 5 )); }, 'my_table');
Whenever data is inserted into person_details
table, set the timestamp field created_at
, so we don't have to specify it everywhere:
$queryBuilder->registerEvent(EventHandler::EVENT_AFTER_INSERT, function(EventArguments $arguments) { $arguments ->getQueryBuilder() ->table('person_details') ->where('id', $insertId) ->update([ 'created_at' => date('Y-m-d H:i:s') ]); }, 'person_details');
After deleting from my_table
delete the relations:
$queryBuilder->registerEvent(EventHandler::EVENT_AFTER_DELETE, function(EventArguments $arguments) { $bindings = $arguments->getQuery()->getBindings(); $arguments ->getQueryBuilder() ->table('person_details') ->where('person_id', $binding[0]) ->delete(); }, 'my_table');
Pixie passes the current instance of query builder as first parameter of your closure so you can build queries with this object, you can do anything like usual query builder (QB
).
If something other than null
is returned from the before-*
query handler, the value will be result of execution and DB will not be actually queried (and thus, corresponding after-*
handler will not be called ether).
Only on after-*
events you get three parameters: first is the query builder, third is the execution time as float and the second varies:
- On
after-query
fires after a raw query has been executed. - On
after-select
you get theresults
obtained fromselect
. - On
after-insert
you get the insert id (or array of ids in case of batch insert) - On
after-delete
you get the query object (same as what you get fromgetQuery()
), from it you can get SQL and Bindings. - On
after-update
you get the query object likeafter-delete
.
Removing event
$queryBuilder->removeEvent($event, $table = null);
Use cases
Here are some cases where Query Events can be extremely helpful:
- Restrict banned users.
- Get only
deleted = 0
records. - Implement caching of all queries.
- Trigger user notification after every entry.
- Delete relationship data after a delete query.
- Insert relationship data after an insert query.
- Keep records of modification after each update query.
- Add/edit created_at and updated _at data after each entry.
Notes
- Query Events are set as per connection basis so multiple database connection don't create any problem, and creating new query builder instance preserves your events.
- Query Events go recursively, for example after inserting into
table_a
your event inserts intotable_b
, now you can have another event registered withtable_b
which inserts intotable_c
. - Of course Query Events don't work with raw queries.
Exceptions
This is a list over exceptions thrown by pecee-pixie.
All exceptions inherit from the base Exception
class.
Getting sql-query from exceptions
If an error occurs and you want to debug your query - you can easily do so as all exceptions thrown by Pixie will contain the last executed query.
You can retrieve the QueryObject
by calling
$sql = $exception->getQueryObject()->getRawSql();
Credits
This project is based on the original Pixie project by the incredible talented usmanhalalit.
Thanks to all the people that have contributed and the users enjoying our library.
Here's some of our references:
Licence
Licensed under the MIT licence.
The MIT License (MIT)
Copyright (c) 2016 Simon Sessingø / pecee-pixie
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.