Jump to content

Funky parameter activity


TechnoDiver
 Share

Go to solution Solved by maxxd,

Recommended Posts

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

Link to comment
Share on other sites

This thread is more than a year old.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.