Download the PHP package stepmuel/sjmsqlayer without Composer
On this page you can find all versions of the php package stepmuel/sjmsqlayer. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download stepmuel/sjmsqlayer
More information about stepmuel/sjmsqlayer
Files in stepmuel/sjmsqlayer
Package sjmsqlayer
Short Description SJMSQLayer simplifies the creation of SQL queries in PHP using a printf-like syntax.
License MIT
Homepage https://github.com/stepmuel/SJMSQLayer
Informations about the package sjmsqlayer
SJMSQLayer
A PHP class to simplify the creation of SQL queries in PHP using dictionaries.
This repository was created for my blog post which contains additional information.
Basic Usage
Query Format Syntax
The query function works similar to printf. The following conversion specifications are available. The code at the end shows the results with an input dictionary {"key1":"value1", "key2":"value2"}.
%@ — quoted value / comma separated list 'value1','value2'
%K — unquoted value / comma separated list value1,value2
%W — where (WHERE %W), key = value, connected with 'AND' key1='value1' AND key2='value2'
%S — assign dictionary key to value (UPDATE SET %A) key1='value1',key2='value2'
%I — insert (INSERT INTO %K %I) (key1,key2) VALUES('value1','value2')
The last example will generate
Using SJMSQLayerStatement
The query function returns a SJMSQLayerStatement object, which has the following properties:
get returns a single row from a SELECT query, getAll returns an array with all rows. getDict will also return all rows, but instead of an array, the result will be a dictionary where each row is addressed by its value of $dictKey. getGroup is used if the value by which the rows are addressed is not unique. It will return a dictionary of arrays. Using the optional parameters $key and $valueKey will fetch single values instead of the whole rows.