Download the PHP package brainstormit/bitbuilder without Composer
On this page you can find all versions of the php package brainstormit/bitbuilder. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download brainstormit/bitbuilder
More information about brainstormit/bitbuilder
Files in brainstormit/bitbuilder
Package bitbuilder
Short Description Easy to read querybuilder with a short learning curve!
License MIT
Homepage https://github.com/BrainstormIT/BITbuilder
Informations about the package bitbuilder
About BITbuilder
BITbuilder is a MySQL querybuilder created by software development interns at Brainstorm IT and uses the PHP Data Objects extension (PDO) for accessing databases. This querybuilder is designed to be as simple as possible with almost no learning curve attached. Laravels querybuilder has been an inspiration to how we wanted the BITbuilder syntax to look like, so syntax wise a few comparisons can be made.
Requirements
- PHP 5.6+
- composer
Installation
You can install BITbuilder through composer:
Get started!
First things first! We need a PDO Database object for BITbuilder to work.
The Database helper class can easily create one (You don't necessarily need to use this).
Navigate to src/helpers/Database.php
and edit your database configurations:
With the database configurations all set up we can create our database object, and even more important: our first BITbuilder object!
Selecting your table
Before we start with the fun stuff we need to select
the table we want to work with.
Let's assume we want to select the users
table:
SELECT statements
If you want to select all users in the users
table we can perform an
SELECT *
with the following:
It's also possible to provide an array with all the fields you want to select:
WHERE clauses
You can add a WHERE
clause to your statement with the following:
A different operator can be provided as second parameter.
The third parameter then becomes the value:
Valid operators: = != < > >= <=
AND & OR operators
OR
& AND
operators can be added to your clauses with the following:
and_
and or_
have an underscore after their method name because PHP doesn't allow PHP reserved names
to be used as method names.
ORDER BY keyword
Ordering a selected record can be done with the following:
The default order is ascending. This can easily be changed by adding DESC
as second parameter:
GROUP BY keyword
Grouping a selected record can be done with the following:
LIMIT keyword
Limiting the amount of items in a record can be done by adding a LIMIT
to your query:
INSERT statements
Inserting a new record into the users
table would look similar to this:
The array which contains your insert info has to be associative.
The array key represents the table field, and the array value represents
the value you want to insert into your table.
DELETE statements
Deleting a record from the users
table would look similar to this:
The second and third parameter represents the WHERE
clause.
A where clause can also be added manually:
The exec()
method is needed to manually execute the query.
UPDATE statements
Updating a record in the users
table would look similar to this:
The array which contains your update info has to be associative, just like the insert()
method.
The array key represents the table field you want to update, and the array value represents
the value.
Just like the delete()
method it's possible to manually add a WHERE
clause if you'd like:
Joins
Let's assume we want to develop a platform where users can post pictures.
If you want to select all pictures that belong to a certain user,
your join would look similar to this:
The table yould want to join with should be passed as the first parameter.
The second and third parameter represent the ON
of the join
Available joins: INNER JOIN (join()), LEFT JOIN (leftJoin()), RIGHT JOIN (rightJoin()), OUTER JOIN (outerJoin())
Executing raw queries
Raw queries can be executed as well:
or:
License
BITbuilder is open-sourced software licensed under the MIT license.