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
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.
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.
- You need a TinyQueries account - if you do not have an account yet sign up here
- You need at least PHP 5.3
- PHP's PDO database layer should be installed
- PHP's cURL lib should be enabled
- A SQL database
- If you want to use the IDE you need a webserver
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 README.md 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 README.md 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.
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 require_once("[path-to-libs]/TinyQueries/libs/DB.php"); // Create database object $db = new TinyQueries\DB(); // Connect to database $db->connect(); // Fetch the result of a query $result = $db->get("helloWorld"); var_dump( $result );