PHP Classes

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

Recommend this page to a friend!
  Info   View files View files (35)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2024-01-09 (2 months ago) RSS 2.0 feedNot enough user ratingsTotal: 659 This week: 1All time: 4,882 This week: 560Up
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  
Name: Rafal Przetakowski <contact>
Classes: 4 packages by
Country: Poland Poland
Age: 45
All time rank: 115528 in Poland Poland
Week rank: 106 Up5 in Poland Poland Up

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  
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

  Files folder image Files  /  DependencyInjection  
File Role Description
Files folder imageCompiler (1 file)
  Plain text file BeeflowSQLQueryManagerExtension.php Class Class source
  Plain text file Configuration.php Class Class source

  Files folder image Files  /  DependencyInjection  /  Compiler  
File Role Description
  Plain text file SQLQueryVartypePass.php Class Class source

  Files folder image Files  /  Exception  
File Role Description
  Plain text file EmptyQueryException.php Class Class source
  Plain text file IncorrectValueTypeException.php Class Class source
  Plain text file NoQueryException.php Class Class source
  Plain text file TypeNotFoundException.php Class Class source

  Files folder image Files  /  Lib  
File Role Description
Files folder imageQuery (1 file)
Files folder imageVartypes (12 files)
  Plain text file QueryToObjectConverter.php Class Class source
  Plain text file SQLQueryManager.php Class Class source

  Files folder image Files  /  Lib  /  Query  
File Role Description
  Plain text file SqlExample.php Class Class source

  Files folder image Files  /  Lib  /  Vartypes  
File Role Description
  Plain text file BFBoolean.php Class Class source
  Plain text file BFByte.php Class Class source
  Plain text file BFDate.php Class Class source
  Plain text file BFDouble.php Class Class source
  Plain text file BFEmail.php Class Class source
  Plain text file BFFloat.php Class Class source
  Plain text file BFInteger.php Class Class source
  Plain text file BFNip.php Class Class source
  Plain text file BFPsqlSecureString.php Class Class source
  Plain text file BFSecureString.php Class Class source
  Plain text file BFString.php Class Class source
  Plain text file VartypeInterface.php Class Class source

  Files folder image Files  /  Resources  
File Role Description
Files folder imageconfig (1 file)

  Files folder image Files  /  Resources  /  config  
File Role Description
  Accessible without login Plain text file services.yml Data Auxiliary data

  Files folder image Files  /  Tests  
File Role Description
Files folder imageSQL (2 files)
  Accessible without login Plain text file bootstrap.php Aux. Auxiliary script
  Plain text file SQLQueryTest.php Class Class source

  Files folder image Files  /  Tests  /  SQL  
File Role Description
  Accessible without login Plain text file emptyQuery.sql Data Auxiliary data
  Accessible without login Plain text file sqlExample.sql Data Auxiliary data

 Version Control Unique User Downloads Download Rankings  
 100%
Total:659
This week:1
All time:4,882
This week:560Up