Get Started with TinyQueries for PHP


Before getting into details about the installation it might be helpful to have an overview of the components of TinyQueries. Basically there are three components

1. Compiler

The compiler is used to convert TinyQueries source code into SQL files. This is done during development only. When your queries are ready, you copy the output of the compiler to the live environment. In the live environment you don't need the compiler anymore.

2. IDE

The IDE is used to create and test queries. Although it's not necessary to use it - you can also just edit the files yourself and compile them using a command line script - it turned out that it's really helpful during the development process. You can regard the IDE as a "phpMyAdmin" for TinyQueries.

3. Client libs

In order to run the SQL code a set of PHP libs have been created. The main class to be used is DB; this is the point of access to connect to the database and to run queries and fetch the results. The client libs are needed both in the development and the live environment.



Start from scratch

If you want to start a new project from scratch then it's recommended to use the API version, available on GitHub. Please follow the instructions in the file.

Integrate with existing PHP-application

If you want to integrate TinyQueries with an existing PHP-application, then it is better to use this version; it supports installation by Composer and you have more freedom in configuring the locations of the TinyQueries source files. Please follow the instructions in the file.

Compile using the online IDE

The IDE is a webservice which you can access by logging in. For the integration with your own development environment it is needed to specify a binding URL. You can specify the binding URL at the Config section of the IDE.

Compile from commandline

If you do not want to use the online IDE, you can compile from the commandline. In the bin folder you can find a bash script for linux and a batch file for windows. If all settings in config/config.xml are set correctly you can just execute the compile script and the SQL files should be refreshed when the script has finished.

Run queries in PHP

You can run a compiled query in PHP as follows:

// Include the libs
// Note: only needed if you have installed the client-libs manually
// If you used Composer you can skip this line

// Create database object
$db = new TinyQueries\DB();

// Connect to database

// Fetch the result of a query
$result = $db->get("helloWorld");

var_dump( $result );

Further reading

Have a look at for some examples of queries and how to use the model. A manual for writing queries can be found here. More info about the IDE can be found here.