dunno where else to put this
how to read the contents of a file and insert it into a database?
tnx![]()
dunno where else to put this
how to read the contents of a file and insert it into a database?
tnx![]()
Please don't mind me. I am just posting a lot of nonsense.
Code:mysql_query('insert into tablename (columnname) values ("' . mysql_real_escape_string(file_get_contents('somefile')) . '");');
Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!
tnx. how about database results save to file?![]()
Please don't mind me. I am just posting a lot of nonsense.
Code:$a = mysql_query('some query or other'); $b = fopen('somefile', 'a'); $c = mysql_fetch_array($a, MYSQL_ASSOC); $d = array(); foreach($c as $e => $f) array_push($f, $e); fwrite($b, implode("\t", $d) . "\n"); do { fwrite($b, implode("\t", $c) . "\n"); } while($c = mysql_fetch_array($a)); fclose($b);
Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!
thnx![]()
Please don't mind me. I am just posting a lot of nonsense.
follow up questionwhat's the difference between include_once() and require_once() in terms of usage? read the php.net manual. need a layperson's explanations. tnx
![]()
Please don't mind me. I am just posting a lot of nonsense.
the code works only reading one line of textOriginally Posted by Twey
is there such a thing as while not EOF { do something }
i want something like:
then in the database:Code:first line of text second line of text
p.s. sorry for not making myself clear on the first postCode:id name 1 first line of text 2 second line of texttnx.
Please don't mind me. I am just posting a lot of nonsense.
include_once issues a warning if it fails. require_once issues an error and stops the execution of the script.
As for the multiple lines
Then just make sure your table has a column with auto incretmentPHP Code:<?php
$lines = file('somefile.txt');
foreach($lines as $num => $line){
mysql_query('insert into tablename (columnname) values ("' . mysql_real_escape_string($line) . '");');
}
?>
no data is being inserted.Originally Posted by blm126
![]()
Please don't mind me. I am just posting a lot of nonsense.
How peculiar. There is, but it shouldn't be necessary here. Try:the code works only reading one line of text
is there such a thing as while not EOF { do something }Code:mysql_query('insert into tablename (columnname) values ("' . mysql_real_escape_string(str_replace("\n", '\n', file_get_contents('somefile'))) . '");');
Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!
Bookmarks