CodeIgniter Forums

Full Version: Posting from CSV to DB but CSV titles have spaces in them, cannot escape?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]Beertastic[/eluser]
Here's an array I'm generating using the first line of a file to create the array keys.
my DB is set up with identical names:

Code:
Array ( [Video Title] => ShowName123 [TV Series] => Show [Season] => 1 [Episode] => 1 }

However, when I use $this->db->insert() to put it into my DB... it created this SQL:

Code:
INSERT INTO `my_table` (`Video` Title, `TV` Series, `Season`, `Episode`) VALUES ('ShowName123', 'Show', '1', '1')

I know that adding 'false' to other functions in active record can escape characters, but how do we escape characters in array KEYS? The spaces in those names are killing me.. and no, I can't change the feed... Sad

El Forum

[eluser]tpetrone[/eluser]

Unless I am missing something ( quite possible ) your array should look like the following.

$array = array(
'Video Title' => 'ShowName123',
'TV Series' => 'Show',
'Season' => 1,
'Episode' =>1
);

Assumption: Your table design actually has 'Video Title', 'TV Series', 'Season' and 'Episode' as defined columns.

If so, then the following ActiveRecord statement "Should" work....

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

Cheers.


El Forum

[eluser]Aken[/eluser]
I'd recommend sanitizing the table's column names into lowercase w/ underscores. Using spaces, capitalization, etc. isn't recommended in naming conventions for databases, for reasons like this. You can then do the same with the feed.

As long as the names are identical, sanitizing them into a proper format shouldn't require changing the feed - you just need to revamp the column names into a different format.

Otherwise worst case scenario, you can create the query manually and escape it however you need.