Welcome Guest, Not a member yet? Register   Sign In
Active Record - inserting
#1

[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?
#2

[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?
#3

[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?
#4

[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 ;-) )
#5

[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.
#6

[eluser]Unknown[/eluser]
asdsdsds




Theme © iAndrew 2016 - Forum software by © MyBB