SafeMySQL is a PHP class for safe and convenient building Mysql queries.
SafeMySQL is a PHP class for safe and convenient handling of Mysql queries.
- safe because <b>every</b> dynamic query part goes into query via <b>placeholder</b>
- convenient because it makes application code short and meaningful, without useless repetitions, making it Extra <abbrtitle="Don't Repeat Yourself">DRY</abbr>
This class is distinguished by three main features
- type-hinted placeholders
- set of helper methods to get the desired result right out of query
- indispensabe **parse()** method which allows to parse placeholders not in the whole query only (like with native prepared statements) but in the arbitary query part
Yet it is very easy to use. You need to learn only few things:
1. You have to **always** pass whatever dynamical data into query via *placeholder*
2. Each placeholder have to be marked with data type. At the moment there are 6 types:
* ?s ("string") - strings (also DATE, FLOAT and DECIMAL)
* ?i ("integer") - the name says it all
* ?n ("name") - identifiers (table and field names)
* ?a ("array") - complex placeholder for IN() operator (substituted with string of 'a','b','c' format, without parentesis)
* ?u ("update") - complex placeholder for SET operator (substituted with string of `field`='value',`field`='value' format)
* ?p ("parsed") - special type placeholder, for inserting already parsed statements without any processing, to avoid double parsing.
3. **No need** for the repetitive binding, fetching and such. Get desired result in the proper format already: