CodeIgniter Forums
Solved - Content of text file into a database - 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: Solved - Content of text file into a database (/showthread.php?tid=14568)

Pages: 1 2


Solved - Content of text file into a database - El Forum - 01-07-2009

[eluser]murphy2006[/eluser]
Hello,

I am thinking of reading from a text file and inserting the content of that file into a database. How would I do this? Search for a solution for hours now.

Code:
<?php

    $data['module']['displayname']     = "Default";
    $data['module']['description']     = 'The default theme';
    $data['module']['version']     = "1.0";
    $data['module']['author']     = "Author Name";
    $data['module']['homepage']    = "http://website.com";

?>

Any ideas?


Solved - Content of text file into a database - El Forum - 01-07-2009

[eluser]xwero[/eluser]
is the code snippet the content of the text file?


Solved - Content of text file into a database - El Forum - 01-07-2009

[eluser]murphy2006[/eluser]
Yes, exactly. I want to read the variables from it.

For example the value of $data['module']['displayname'] goes into displayname in the database.

Thanks!


Solved - Content of text file into a database - El Forum - 01-07-2009

[eluser]xwero[/eluser]
why not include it and use the array?
Code:
include('path/to/file/file_name.php');
print_r($data['module']);



Solved - Content of text file into a database - El Forum - 01-07-2009

[eluser]murphy2006[/eluser]
perfect all I needed, 1000 thanks!


Solved - Content of text file into a database - El Forum - 01-07-2009

[eluser]murphy2006[/eluser]
Works fine in a view file but how can I use it in a controller?
I get the "Cannot modify header information - headers already sent..."

Thanks again.


Solved - Content of text file into a database - El Forum - 01-07-2009

[eluser]xwero[/eluser]
don't output the array.


Solved - Content of text file into a database - El Forum - 01-07-2009

[eluser]murphy2006[/eluser]
But then I cannot get the data from the file for insertion into the database (in the controller).
How would it look exactly?


Solved - Content of text file into a database - El Forum - 01-07-2009

[eluser]Popcorn[/eluser]
murphy2006, no offence but I think you need to go back and learn PHP.

Clue, you loop the $data array.


Solved - Content of text file into a database - El Forum - 01-07-2009

[eluser]xwero[/eluser]
Code:
include('path/to/file/file_name.php');
$this->db->set($data['module']);
This is of course if the fieldnames of the database table are the same as the array keys.