TechnoDiver Posted September 14, 2021 Share Posted September 14, 2021 I'm experiencing something that I've no idea how to understand it. I have the following methods -> <?php public function action($action, $table, $where = [], $rule = "") { if(count($where) === 3) { $operators = array('=', '<', '>', '<=', '<='); $field = $where[0]; $operator = $where[1]; $value = $where[2]; if(in_array($operator, $operators)) { if($rule == "") { $sql = "{$action} FROM {$table} WHERE {$field} {$operator} ?"; } else { $sql = "{$action} FROM {$table} WHERE {$field} {$operator} ? {$rule}"; } if(!$this->query($sql, array($value))->error()) { return $this; } } } return false; } // public function get($table, $where = [], $column = "*", $rule = "") { // return $this->action("SELECT {$column}", $table, $where, $rule); // } public function get($table, $where = [], $rule = "") { return $this->action("SELECT *", $table, $where, $rule); } They're called like this -> <?php public function recent() { $rule = "ORDER BY RAND()"; $field = "type"; $type = "recent"; $query = $this->_db->get(self::$_table, array($field, "=", $type), $rule); print_r($query); } The code like it is here works. Where the weirdness comes in is if I use the commented out DB->get() method. When I switch it and use the get() method that is commented out in the above code I get a fatal error because it's parsing the query string as this -> Quote ORDER BY RAND() FROM posts WHERE type = 'breaking'' The absolute only difference is adding in that $column parameter or not and when it's there this effed up query string is the result. Can one of you fine phreaks break it down for me, I've been staring at my code for an hour and can't figure it out. Thanks Quote Link to comment Share on other sites More sharing options...
Solution maxxd Posted September 14, 2021 Solution Share Posted September 14, 2021 In the commented out version, $column is between $where and $rule. So, when you use the second block of code on the commented-out version of get(), 'OREDER BY RAND()' becomes $column and $rule is blank. 1 Quote Link to comment Share on other sites More sharing options...
TechnoDiver Posted September 14, 2021 Author Share Posted September 14, 2021 1 hour ago, maxxd said: In the commented out version, $column is between $where and $rule. So, when you use the second block of code on the commented-out version of get(), 'OREDER BY RAND()' becomes $column and $rule is blank. It seems so obvious now, Thank you Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.