Loading txt into MySQL with PHP: only integer values import
Posted: Mon Oct 06, 2008 7:38 am
Greetings from a Newbie, and my thanks. I am trying to automate the loading of a syslog text file into mysql using php. After connecting to the db, I'm using this code:
$fileHandle= @fopen($filename, "r");
if ($fileHandle) {
while (!feof($fileHandle)) {
$line = fgets($fileHandle, 4096);
$dataArray = preg_split("/\s+/", $line);
mysql_query('INSERT INTO `syslogscans`.`tablename` (`field1`, `field2`, etc....) VALUES ($dataArray[1] . ', ' . $dataArray[2] . etc.....);
}
fclose($fileHandle);
}
THE PROBLEM: All fields in the text file containing only integer values DO import (some of those being varchar some int). All fields in the text file containing any string data will NOT import. Any suggestions as to cause & solution would be greatly appreciated. Thank you.
$fileHandle= @fopen($filename, "r");
if ($fileHandle) {
while (!feof($fileHandle)) {
$line = fgets($fileHandle, 4096);
$dataArray = preg_split("/\s+/", $line);
mysql_query('INSERT INTO `syslogscans`.`tablename` (`field1`, `field2`, etc....) VALUES ($dataArray[1] . ', ' . $dataArray[2] . etc.....);
}
fclose($fileHandle);
}
THE PROBLEM: All fields in the text file containing only integer values DO import (some of those being varchar some int). All fields in the text file containing any string data will NOT import. Any suggestions as to cause & solution would be greatly appreciated. Thank you.