PHP Classes

Simple SQL query manager: Compose SQL queries read from template files

Recommend this page to a friend!
     
  Info   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 659 All time: 4,885 This week: 45Up
Version License PHP version Categories
sql_query_manager 1.0.28GNU General Publi...5.3PHP 5, Databases, Templates, Security
Description 

Author

This class can compose SQL queries read from template files.

It can read and process a template file that defines a SQL query.

The class replaces placeholder using values assigned to class variables.

The values are encoded before replacing in the template according to the variable type.

The processed query template is returned as a string.

Picture of Rafal Przetakowski
  Performance   Level  

 

Details

# Simple SQL query manager A simple SQL query manager with option to secure queries by setting parameter type. It uses classes which represents siple var types as string, integer etc... and own classes like secureString, email etc... To better secure queries, you can create your own var types classes, for example password or phone ## Install ### composer $ composer require "beeflow/sqlquerymanager:dev-master" ### GIT $ git clone https://github/beeflow/ and then add to `app/AppKernel.php` public function registerBundles() { ... new Beeflow\SQLQueryManager\SQLQueryBundle(), } To add new Vartype just insert into your `services.yml` app.YourVarType: class: YourBundle\Lib\Vartypes\YourVarType; tags: - { name: beeflow.sql_manager.vartype, alias: yourVarTypeAlias } and now you can use it in SQL query: SELECT example1 FROM exampleTable WHERE example = {value->yourVarTypeAlias} ## Examples ### SQL query example: SELECT example1 FROM exampleTable WHERE example = {value->secureString} ### Using SQLQueryManager as Symfony service In your Controller: $sqlManager = $this->get('beeflow.sql_query_manager'); Set default directory with SQL files $slqlManager->setSqlDirectory('sql_directory'); Use query as a method with temporary different directory with SQL files: $slqlManager->sqlExample([ 'value' => 'TEST_VALUE', 'value2' => 11, 'vatno' => '1111111111', 'valueArrayWithoutAtype' => array('one', 'two', 'tree') ], 'someTmpDirectory'); ### Example with new method of calling SQL files `<?php use Beeflow\SQLQueryManager\SQLQuery try { $query = new SQLQuery(); $query->sqlExample([ 'value' => 'TEST_VALUE', 'value2' => 11, 'vatno' => '1111111111', 'valueArrayWithoutAtype' => array('one', 'two', 'tree') ]); echo $query->getQuery(); } catch (Exception $ex) { echo $ex->getMessage(); }` ### Example with a correct data: `<?php use Beeflow\SQLQueryManager\SQLQuery try { $query = new SQLQuery("sqlExample"); $query->value = 'TEST_VALUE'; // if you set a string value it will be set as 0 (zero) because (integer)'ddd' = 0 (zero) $query->value2 = 11; // polish vat no algoritm allows to use 1111111111 vat number // if you want to check an european vat no see: // http://www.phpclasses.org/package/2280-PHP-Check-if-a-European-VAT-number-is-valid.html $query->vatno = '1111111111'; $query->valueArrayWithoutAtype = array('one', 'two', 'tree'); $query->valueWithoutParamType = "value Without Param Type"; echo $query->getQuery(); } catch (Exception $ex) { echo $ex->getMessage(); }` ### Example with incorrect data: `<?php use Beeflow\SQLQueryManager\SQLQuery try { $newQuery = new SQLQuery("sqlExample"); $newQuery->value = 'TEST_VALUE'; $newQuery->value2 = 11; // incorrect polish vat no $newQuery->vatno = '1212111211'; $query->valueArrayWithoutAtype = array('one', 'two', 'tree'); $query->valueWithoutParamType = "value Without Param Type"; echo $newQuery->getQuery(); } catch (Exception $ex) { echo $ex->getMessage(); }` ### Example with conditioned value: `<?php use Beeflow\SQLQueryManager\SQLQuery try { $query = new SQLQuery("sqlExample"); $query->value = 'TEST_VALUE'; // if you set a string value it will be set as 0 (zero) because (integer)'ddd' = 0 (zero) $query->value2 = 11; $query->vatno = '1111111111'; $query->valueArrayWithoutAtype = array('one', 'two', 'tree'); $query->valueWithoutParamType = "value Without Param Type"; // condition !empty() $query->notEmptyValue = 1; echo $query->getQuery(); } catch (Exception $ex) { echo $ex->getMessage(); }`

  Files folder image Files (35)  
File Role Description
Files folder imageDependencyInjection (2 files, 1 directory)
Files folder imageException (4 files)
Files folder imageLib (2 files, 2 directories)
Files folder imageResources (1 directory)
Files folder imageTests (2 files, 1 directory)
Accessible without login Plain text file autoload.php Aux. Auxiliary script
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file composer.lock Data Auxiliary data
Accessible without login Plain text file LICENSE Data Auxiliary data
Accessible without login Plain text file phpunit.xml.dist Data Auxiliary data
Accessible without login Plain text file README.md Doc. Auxiliary data
Plain text file SQLQuery.php Class Class source
Plain text file SQLQueryBundle.php Class Class source

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:659
This week:0
All time:4,885
This week:45Up