@@ -17,6 +17,14 @@ class Query extends Connector
1717 */
1818 protected $ statement ;
1919
20+ /**
21+ * Array with questions marks for
22+ * prepared statement SQL
23+ *
24+ * @var array
25+ */
26+ protected $ questionMarks = [];
27+
2028 public function __construct ()
2129 {
2230 parent ::__construct ();
@@ -40,14 +48,34 @@ public function get()
4048 )->fetchAll ($ this ->statement );
4149 }
4250
51+ /**
52+ * Prepared SQL statement
53+ *
54+ * Prepare SQL statement and bind
55+ * values with question marks.
56+ * Can be used with Insert and
57+ * Delete classes.
58+ *
59+ * @return bool
60+ */
61+ public function push ()
62+ {
63+ $ processing = $ this ->prepare (
64+ $ this ->convertSQLToString ($ this ->sql )
65+ )->bind ($ this ->statement , $ this ->values );
66+
67+ return $ processing ;
68+
69+ }
70+
4371 /**
4472 * This is abstaraction of fetchAll PDO method
4573 *
4674 * @param \PDOStatement $statement
4775 *
4876 * @return array
4977 */
50- public function fetchAll (\PDOStatement $ statement )
78+ protected function fetchAll (\PDOStatement $ statement )
5179 {
5280 return $ statement ->fetchAll ();
5381 }
@@ -59,7 +87,7 @@ public function fetchAll(\PDOStatement $statement)
5987 *
6088 * @return string
6189 * */
62- public function fetchColumn (\PDOStatement $ statement )
90+ protected function fetchColumn (\PDOStatement $ statement )
6391 {
6492 return $ statement ->fetchColumn ();
6593 }
@@ -71,12 +99,41 @@ public function fetchColumn(\PDOStatement $statement)
7199 *
72100 * @return \Manipulator\SQL\Select
73101 */
74- public function query (string $ query )
102+ protected function query (string $ query )
75103 {
76104 $ this ->statement = $ this ->connection ()->query ($ query );
77105 return $ this ;
78106 }
79107
108+ /**
109+ * Prepare SQL statement
110+ *
111+ * Assign statement property \PDOStatement object
112+ * and return reference on this class
113+ *
114+ * @param string $query
115+ *
116+ * @return \Manipulator\SQL\Query
117+ */
118+ protected function prepare (string $ query )
119+ {
120+ $ this ->statement = $ this ->connection ->prepare ($ query );
121+ return $ this ;
122+ }
123+
124+ /**
125+ * Bind values with question marks into SQL statement
126+ *
127+ * @param \PDOStatement $statement
128+ * @param array $values
129+ *
130+ * @return bool
131+ */
132+ protected function bind (\PDOStatement $ statement , array $ values )
133+ {
134+ return $ statement ->execute ($ values );
135+ }
136+
80137 /**
81138 * Convert passed SQL statement like array
82139 * in to string
@@ -85,9 +142,39 @@ public function query(string $query)
85142 *
86143 * @return string
87144 */
88- public function convertSQLToString (array $ sql )
145+ protected function convertSQLToString (array $ sql )
89146 {
90147 return $ this ->parser ->convertToString ($ sql , ' ' );
91148 }
92149
150+ /**
151+ * Convert columns from sql to
152+ * array
153+ *
154+ * @param string $columns
155+ *
156+ * @return array
157+ */
158+ protected function convertColumnsToArray (string $ values )
159+ {
160+ return $ this ->parser ->convertToArray ($ values , ', ' );
161+ }
162+
163+ /**
164+ * Generat question marks for prepared statement SQL
165+ *
166+ * @param array $columns
167+ *
168+ * @return array;
169+ */
170+ public function questionMarksGenerator (array $ columns )
171+ {
172+ foreach ($ columns as $ column )
173+ {
174+ $ this ->questionMarks [] = $ column = '? ' ;
175+ }
176+
177+ return $ this ->parser ->convertToString ($ this ->questionMarks , ', ' );
178+ }
179+
93180}
0 commit comments