From c1cb308188d744eb1e7de58f4191e7879d6a41e8 Mon Sep 17 00:00:00 2001
From: colshrapnel
Date: Tue, 28 Mar 2017 18:45:14 +0300
Subject: [PATCH 1/4] Create .gitattributes
---
.gitattributes | 1 +
1 file changed, 1 insertion(+)
create mode 100644 .gitattributes
diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 0000000..390c50f
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1 @@
+*.md text
From 0afa8ddfc2a6247c00a5c62d9b4677eb78bba21d Mon Sep 17 00:00:00 2001
From: colshrapnel
Date: Tue, 28 Mar 2017 18:59:18 +0300
Subject: [PATCH 2/4] Delete README.md
---
README.md | Bin 4979 -> 0 bytes
1 file changed, 0 insertions(+), 0 deletions(-)
delete mode 100644 README.md
diff --git a/README.md b/README.md
deleted file mode 100644
index 5c0d20fbebd6e48cfe57be87b29d4ec134eba8f3..0000000000000000000000000000000000000000
GIT binary patch
literal 0
HcmV?d00001
literal 4979
zcmbtYZExE+65h}H6|;dCP6XLSyZh;y7vx%Z*SIw4#@;&=hebn6w9N}8x}+4x|NfpC
zO17H5Y!6o;bz+gj;mkA7JfoRf>bJYu?^nrL_b*9i-IrtnDSG$YJIbvJftJowz(Z11
zLAk3QbY*l^(;9zUQ?1A?NvzSwMth^fI2jRJqlL~@6EvMJ&h>-#yVGZjb1HU~Dorkn
zceGKyrj^ryOjSFo*SdZ1U=;7$Se5IwvxWA&8+_&uQ$3jyenjEi7y44!=Zkxy&4YbR4o>su*B-K
zqt~t))^v+Ks;2j@@vyQyI)8op{`48IJ5Q4N8ZnH~!!LyiHB2@ptaU+)9d7Bh#zCf{
zC5$v)2VCrr%9?w)T*F=E3$kY66~{AUXJDrZ>{y!CyNw>L5ieNl#V4d`CduL;rl~}{
z#POR<&
zA*Vst43V|A8|{$?#J-RRD?DId3mss*faTEGn!H)9u>)RW*B%gm>0_=cMib!Hj|n{H
z+lrknaMZ!eRd$!rLP8-Am0y@z`CSi}8TD?#j_`HEMpr>0jA<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r5Lk$REn4k6CFxar?%5CN%8K%r*CYfP4*rk1V|*_}
mo%LhP`C~1RzUNvqw+yiivM6yAg|Ss6VvFT7`R_@Ba&J9-J8f
From 1d851923c8e9f012eeaa85c052034c4c453ed614 Mon Sep 17 00:00:00 2001
From: colshrapnel
Date: Tue, 28 Mar 2017 18:59:58 +0300
Subject: [PATCH 3/4] Create README.md
---
README.md | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 74 insertions(+)
create mode 100644 README.md
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..2ed6a98
--- /dev/null
+++ b/README.md
@@ -0,0 +1,74 @@
+SafeMySQL
+=========
+
+SafeMySQL is a PHP class for safe and convenient handling of MySQL queries.
+- Safe because every dynamic query part goes into the query via placeholder
+- Convenient because it makes application code short and meaningful, without useless repetitions, making it ''extra'' DRY
+
+This class is distinguished by three main features
+- Unlike standard libraries, it is using **type-hinted placeholders**, for the **everything** that may be put into the query
+- Unlike standard libraries, it requires no repetitive binding, fetching and such,
+thanks to set of helper methods to get the desired result right out of the query
+- Unlike standard libraries, it can parse placeholders not in the whole query only, but in the arbitary query part,
+thanks to the indispensabe **parse()** method, making complex queries as easy and safe as regular ones.
+
+Yet, it is very easy to use. You need to learn only a few things:
+
+1. You have to **always** pass whatever dynamical data into the query via *placeholder*
+2. Each placeholder have to be marked with data type. At the moment there are six 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. To get data right out of the query there are helper methods for the most used:
+ * query($query,$param1,$param2, ...) - returns mysqli resource.
+ * getOne($query,$param1,$param2, ...) - returns scalar value
+ * getRow($query,$param1,$param2, ...) - returns 1-dimensional array, a row
+ * getCol($query,$param1,$param2, ...) - returns 1-dimensional array, a column
+ * getAll($query,$param1,$param2, ...) - returns 2-dimensional array, an array of rows
+ * getInd($key,$query,$par1,$par2, ...) - returns an indexed 2-dimensional array, an array of rows
+ * getIndCol($key,$query,$par1,$par2, ...) - returns 1-dimensional array, an indexed column, consists of key => value pairs
+4. For the whatever complex case always use the **parse()** method. And insert
+
+The rest is as usual - just create a regular SQL (with placeholders) and get a result:
+
+* ```$name = $db->getOne('SELECT name FROM table WHERE id = ?i',$_GET['id']);```
+* ```$data = $db->getInd('id','SELECT * FROM ?n WHERE id IN (?a)','table', array(1,2));```
+* ```$data = $db->getAll("SELECT * FROM ?n WHERE mod=?s LIMIT ?i",$table,$mod,$limit);```
+
+The main feature of this class is a type-hinted placeholders.
+And it's a really great step further from just ordinal placeholders used in prepared statements.
+Simply because dynamical parts of the query aren't limited to just scalar data!
+In the real life we have to add identifiers, arrays for ```IN``` operator, and arrays for ```INSERT``` and ```UPDATE``` queries.
+So - we need many different types of data formatting. Thus, we need the way to tell the driver how to format this particular data.
+Conventional prepared statements use toilsome and repeating bind_* functions.
+But there is a way more sleek and useful way - to set the type along with placeholder itself. It is not something new - well-known ```printf()``` function uses exactly the same mechanism. So, I hesitated not to borrow such a brilliant idea.
+
+To implement such a feature, no doubt one have to have their own query parser. No problem, it's not a big deal. But the benefits are innumerable.
+Look at all the questions on Stack Overflow where developers are trying in vain to bind a field name.
+Voila - with the identifier placeholder it is as easy as adding a field value:
+
+```php
+$field = $_POST['field'];
+$value = $_POST['value'];
+$sql = "SELECT * FROM table WHERE ?n LIKE ?s";
+$data = $db->query($sql,$field,"%$value%");
+```
+
+Nothing could be easier!
+
+Of course we will have placeholders for the common types - strings and numbers.
+But as we started inventing new placeholders - let's make some more!
+
+Another trouble in creating prepared queries - arrays going to the IN operator. Everyone is trying to do it their own way, but the type-hinted placeholder makes it as simple as adding a string:
+
+```php
+$array = array(1,2,3);
+$data = $db->query("SELECT * FROM table WHERE id IN (?a)",$array);
+```
+
+The same goes for such toilsome queries like ```INSERT``` and ```UPDATE```.
+
+And, of course, we have a set of helper functions to turn type-hinted placeholders into real brilliant, making almost every call to the database as simple as one or two lines of code for all the regular real life tasks.
From bdb8cf6ba59370359c6fa5af66a79bdb14f3a55f Mon Sep 17 00:00:00 2001
From: colshrapnel
Date: Tue, 28 Mar 2017 19:01:13 +0300
Subject: [PATCH 4/4] Delete .gitattributes
---
.gitattributes | 1 -
1 file changed, 1 deletion(-)
delete mode 100644 .gitattributes
diff --git a/.gitattributes b/.gitattributes
deleted file mode 100644
index 390c50f..0000000
--- a/.gitattributes
+++ /dev/null
@@ -1 +0,0 @@
-*.md text