File tree Expand file tree Collapse file tree 1 file changed +15
-8
lines changed
Expand file tree Collapse file tree 1 file changed +15
-8
lines changed Original file line number Diff line number Diff line change @@ -28,6 +28,7 @@ class QueryBuilder
2828
2929 /**
3030 * @param PDO $pdo
31+ * @param bool $printErrors
3132 */
3233 public function __construct (PDO $ pdo , bool $ printErrors = false )
3334 {
@@ -568,17 +569,23 @@ public function having($having): QueryBuilder
568569 }
569570
570571 /**
571- * @param array|string $cond
572+ * @param array|string $field
573+ * @param string $value
572574 * @return $this
573575 */
574- public function like ($ cond = [] ): QueryBuilder
576+ public function like ($ field , string $ value = '' ): QueryBuilder
575577 {
576- if ($ cond ) {
577- if (is_string ($ cond )) {
578- $ this ->where ($ cond );
579- } else if (is_array ($ cond )) {
580- $ this ->where ([[$ cond [0 ], 'LIKE ' , $ cond [1 ]]]);
581- }
578+ if (empty ($ field )) {
579+ $ this ->setError ('Empty $field in ' . __METHOD__ );
580+ return $ this ;
581+ }
582+
583+ if (is_string ($ field ) && !empty ($ field ) && is_string ($ value ) && !empty ($ value )) {
584+ $ this ->where ([[$ field , 'LIKE ' , $ value ]]);
585+ } else if (is_string ($ field ) && empty ($ value )) {
586+ $ this ->where ($ field );
587+ } else if (is_array ($ field )) {
588+ $ this ->where ([[$ field [0 ], 'LIKE ' , $ field [1 ]]]);
582589 }
583590
584591 return $ this ;
You can’t perform that action at this time.
0 commit comments