beeflow/sqlquerymanager
Simple SQL query manager for PHP/Symfony. Load SQL from files and safely inject parameters using typed placeholders (string, int, secureString, email, etc.), with support for custom vartypes via service tags. Use as a Symfony service or via the SQLQuery class.
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
$ composer require "beeflow/sqlquerymanager:dev-master"
$ 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}
SELECT example1 FROM exampleTable WHERE example = {value->secureString}
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');
`<?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();
}`
`<?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();
}`
`<?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();
}`
`<?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();
}`
How can I help you explore Laravel packages today?