CodeIgniter Forums
Active Record - inserting - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Active Record - inserting (/showthread.php?tid=42203)



Active Record - inserting - El Forum - 05-30-2011

[eluser]ericbae[/eluser]
I'm a little puzzled. Here's what I have

$this->db->insert("my_table", array('name' => $whatever));

when I do the above, it fails if $whatever is a set of words (e.g. "hello hello hello").

Only way I can get above working is if I write it like

$this->db->insert("my_table", array('name' => "$whatever"));

I thought the quotes were not necessary? Am I missing something?


Active Record - inserting - El Forum - 05-30-2011

[eluser]LuckyFella73[/eluser]
Strange that it works only the way with the qoutes..

I would do it like the userguide says.
Code:
// define array first
$data = array(
   'title' => 'My title' ,
   'name' => 'My Name' ,
   'date' => 'My date'
);

$this->db->insert('mytable', $data);

In my opinion your first approach should work - no idea what
the problem is with that. What kind of error message do you get?


Active Record - inserting - El Forum - 05-30-2011

[eluser]ericbae[/eluser]
It looks like CodeIgniter is not wrapping it up like '{$whatever}', as it says in the user guide. So the error complains about the fact that you can have something like

insert into A (c1) values (hello hello hello)

It should be

insert into A (c1) values ("hello hello hello")

automatically right?


Active Record - inserting - El Forum - 05-30-2011

[eluser]theprodigy[/eluser]
I use the first way all the time.
Would you mind posting the full function that you are using? (and don't forget to use the code tags, it makes it easier to read ;-) )


Active Record - inserting - El Forum - 06-01-2011

[eluser]ericbae[/eluser]
hm. ok. I think I know what the problem is. I am using SimpleXML to get my data values, that I am inserting via Active Record, but SimpleXML_load_file returns "object" instead of string. And CI doesn't have "insert quotation marks if data value is object" condition.


Active Record - inserting - El Forum - 06-01-2011

[eluser]Unknown[/eluser]
asdsdsds