Welcome Guest, Not a member yet? Register   Sign In
Problem with quotes around field values in 1.6.3
#1

[eluser]steelaz[/eluser]
I have this code in my model:
Code:
$data['job_id']    = $job_id;
$data['type']      = $type;
$data['text']      = $text;
$data['timestamp'] = time();
        
$this->db->insert('events', $data);

For some reason CI doesn't put quotes around 'text' field and it produces flowing query, which returns an error :

Code:
INSERT INTO `events` (`job_id`, `type`, `text`, `timestamp`) VALUES ('7', 'error', Requested IP address [208.43.3.25] is not available! , 1229007771)

How (where) does CI decide if field should have quotes around value ('timestamp' also doesn't have quotes, but it's an integer)?
#2

[eluser]Nick Husher[/eluser]
What database type is the field "text"? CI probably only encapsulates certain "stringy" types in quotes. Also, what type is the value you're assigning to text? If it doesn't return 'string' to the function gettype, CI won't escape it. Here's the escape code:

Code:
@line 675 of DB_driver.php
    function escape($str)
    {    
        switch (gettype($str))
        {
            case 'string'    :    $str = "'".$this->escape_str($str)."'";
                break;
            case 'boolean'    :    $str = ($str === FALSE) ? 0 : 1;
                break;
            default            :    $str = ($str === NULL) ? 'NULL' : $str;
                break;
        }        

        return $str;
    }
#3

[eluser]steelaz[/eluser]
Database type for "text" is TEXT as opposed to "type" which is VARCHAR. The value was "Requested IP address [208.43.3.25] is not available!", so gettype($str) is returning 'string'.

I don't have time right now to run more test, so I just changed it to regular query string and did $this->db->query($string)). Thanks for pointing out DB_driver.php I will run some more tests when I get a chance.




Theme © iAndrew 2016 - Forum software by © MyBB