@@ -96,7 +96,7 @@ public function select(OrmQueryInterface $data)
9696 }
9797 $ sql = trim ("SELECT $ column FROM ` {$ table }` {$ where } {$ orderby } {$ limit }" );
9898 $ sql .= '; ' ;
99- return $ this ->query ($ sql ,$ bind ,[
99+ return $ this ->query ($ sql ,[] ,[
100100 'isSingle ' => $ isSingle ,
101101 'isColumn ' => $ isColumn ,
102102 'isRow ' => $ isRow ,
@@ -115,9 +115,9 @@ public function select(OrmQueryInterface $data)
115115 */
116116 public function query ($ sql , $ bind = null , $ args = [])
117117 {
118- $ isSingle = isset ($ args ['isSingle ' ]) ? $ args ['isSingle ' ] : false ;
119- $ isColumn = isset ($ args ['isColumn ' ]) ? $ args ['isColumn ' ] : false ;
120- $ isRow = isset ($ args ['isRow ' ]) ? $ args ['isRow ' ] : false ;
118+ $ isSingle = isset ($ args ['isSingle ' ]) ? $ args ['isSingle ' ] : false ;
119+ $ isColumn = isset ($ args ['isColumn ' ]) ? $ args ['isColumn ' ] : false ;
120+ $ isRow = isset ($ args ['isRow ' ]) ? $ args ['isRow ' ] : false ;
121121 $ fetchMode = isset ($ args ['fetchMode ' ]) ? $ args ['fetchMode ' ] : null ;
122122
123123 if ( $ isSingle ) {
@@ -145,19 +145,19 @@ public function save($id = null)
145145 $ id = !empty ($ this ->data [$ this ->key ])
146146 ? intval ($ this ->data [$ this ->key ]) : 0 ;
147147 }
148- $ field = '' ;
148+ $ fields = '' ;
149149 $ columns = Arrayify::keys ($ this ->data );
150150 foreach ($ columns as $ column ) {
151151 if ( $ column !== $ this ->key ) {
152- $ field .= "{$ column } = : {$ column }, " ;
152+ $ fields .= "` {$ column }` = : {$ column }, " ;
153153 }
154154 }
155- $ field = Stringify::subreplace ($ field ,'' ,-1 ,1 );
155+ $ fields = Stringify::subreplace ($ fields ,'' ,-1 ,1 );
156156 if ( count ($ columns ) > 1 ) {
157- $ sql = "UPDATE ` {$ this ->table }` SET {$ field } WHERE {$ this ->key } = : {$ this ->key }; " ;
157+ $ sql = "UPDATE ` {$ this ->table }` SET {$ fields } WHERE ` {$ this ->key }` = : {$ this ->key }; " ;
158158 if ( $ id === 0 ) {
159159 unset($ this ->data [$ this ->key ]);
160- $ sql = "UPDATE ` {$ this ->table }` SET {$ field }; " ;
160+ $ sql = "UPDATE ` {$ this ->table }` SET {$ fields }; " ;
161161 }
162162 return $ this ->execute ($ sql );
163163 }
@@ -175,9 +175,14 @@ public function create() : int
175175 {
176176 $ bind = $ this ->data ;
177177 if ( !empty ($ bind ) ) {
178- $ fields = Arrayify::keys ($ bind );
179- $ field = [implode (', ' ,$ fields ),": " . implode (',: ' ,$ fields )];
180- $ sql = "INSERT INTO ` {$ this ->table }` ( {$ field [0 ]}) VALUES ( {$ field [1 ]}); " ;
178+ $ bind = Arrayify::keys ($ bind );
179+ $ columns = [];
180+ foreach ($ bind as $ key => $ column ) {
181+ $ columns [$ key ] = "` {$ column }` " ;
182+ }
183+ $ fields = implode (', ' ,$ columns );
184+ $ values = ': ' . implode (',: ' ,$ bind );
185+ $ sql = "INSERT INTO ` {$ this ->table }` ( {$ fields }) VALUES ( {$ values }); " ;
181186 } else {
182187 $ sql = "INSERT INTO ` {$ this ->table }` () VALUES (); " ;
183188 }
@@ -197,7 +202,7 @@ public function delete($id = null) : int
197202 $ id = !empty ($ this ->data [$ this ->key ])
198203 ? intval ($ this ->data [$ this ->key ]) : 0 ;
199204 }
200- $ sql = "DELETE FROM ` {$ this ->table }` WHERE {$ this ->key } = : {$ this ->key } LIMIT 1; " ;
205+ $ sql = "DELETE FROM ` {$ this ->table }` WHERE ` {$ this ->key }` = : {$ this ->key } LIMIT 1; " ;
201206 $ bind = [$ this ->key => $ id ];
202207 return $ this ->execute ($ sql ,$ bind );
203208 }
@@ -215,31 +220,31 @@ public function find($id = null)
215220 $ id = !empty ($ this ->data [$ this ->key ])
216221 ? intval ($ this ->data [$ this ->key ]) : 0 ;
217222 }
218- $ sql = "SELECT * FROM ` {$ this ->table }` WHERE {$ this ->key } = : {$ this ->key } LIMIT 1; " ;
223+ $ sql = "SELECT * FROM ` {$ this ->table }` WHERE ` {$ this ->key }` = : {$ this ->key } LIMIT 1; " ;
219224 $ bind = [$ this ->key => $ id ];
220225 $ result = $ this ->db ->row ($ sql ,$ bind );
221226 return $ this ->data = ($ result ) ? $ result : null ;
222227 }
223228
224229 /**
225- * Search table objects by fields
230+ * Search table objects by bind
226231 *
227232 * @access public
228- * @param array $fields
233+ * @param array $bind
229234 * @param array $sort
230235 * @return mixed
231236 */
232- public function search ($ fields = [], $ sort = [])
237+ public function search ($ bind = [], $ sort = [])
233238 {
234- $ bind = empty ($ fields ) ? $ this ->data : $ fields ;
239+ $ bind = empty ($ bind ) ? $ this ->data : $ bind ;
235240 $ sql = "SELECT * FROM ` {$ this ->table }` " ;
236241 if ( !empty ($ bind ) ) {
237- $ field = [];
242+ $ fields = [];
238243 $ columns = Arrayify::keys ($ bind );
239244 foreach ($ columns as $ column ) {
240- $ field [] = "{$ column } = : {$ column }" ;
245+ $ fields [] = "` {$ column }` = : {$ column }" ;
241246 }
242- $ sql .= " WHERE " . implode (" AND " ,$ field );
247+ $ sql .= " WHERE " . implode (" AND " ,$ fields );
243248 }
244249 if ( !empty ($ sort ) ) {
245250 $ sorted = [];
@@ -252,24 +257,24 @@ public function search($fields = [], $sort = [])
252257 }
253258
254259 /**
255- * Search table object by fields
260+ * Search table object by bind
256261 *
257262 * @access public
258- * @param array $fields
263+ * @param array $bind
259264 * @param array $sort
260265 * @return mixed
261266 */
262- public function searchOne ($ fields = [], $ sort = [])
267+ public function searchOne ($ bind = [], $ sort = [])
263268 {
264- $ bind = empty ($ fields ) ? $ this ->data : $ fields ;
269+ $ bind = empty ($ bind ) ? $ this ->data : $ bind ;
265270 $ sql = "SELECT * FROM ` {$ this ->table }` " ;
266271 if ( !empty ($ bind ) ) {
267- $ field = [];
272+ $ fields = [];
268273 $ columns = Arrayify::keys ($ bind );
269274 foreach ($ columns as $ column ) {
270- $ field [] = "{$ column } = : {$ column }" ;
275+ $ fields [] = "` {$ column }` = : {$ column }" ;
271276 }
272- $ sql .= ' WHERE ' . implode (' AND ' ,$ field );
277+ $ sql .= ' WHERE ' . implode (' AND ' ,$ fields );
273278 }
274279 if ( !empty ($ sort ) ) {
275280 $ sorted = [];
@@ -391,7 +396,7 @@ public function deleteAll($table = '') : int
391396 }
392397
393398 /**
394- * Delete all from table
399+ * Reset table Id.
395400 *
396401 * @access public
397402 * @param string $table
@@ -446,9 +451,22 @@ public function createDatabase()
446451 die ("ERROR : {$ e ->getMessage ()}" );
447452 }
448453 }
454+
455+ /**
456+ * Check table.
457+ *
458+ * @access public
459+ * @param string $table
460+ * @return bool
461+ */
462+ public function hasTable ($ table = '' )
463+ {
464+ $ sql = "SHOW TABLES LIKE ' {$ table }'; " ;
465+ return (bool )$ this ->db ->query ($ sql );
466+ }
449467
450468 /**
451- * Get application tables
469+ * Get tables.
452470 *
453471 * @access public
454472 * @param void
0 commit comments