shane2006 Posted July 7, 2007 Share Posted July 7, 2007 Headbanger here. We download csv files (telephone records), parse them, do a little manipulation and insert them into a mysql database. We need to insert data into the database that does not exist in the csv files. The new data is simply a concat of text and an existing field. In mysql, it would be a simple command - concat("V2_",field0). However, when we try to do it in the php script, it fails with a "Check the manual . . . for the right syntax". The script works fine without the language marked by **language**. Is there a prohibition that we are unaware of? We have tried to insert the concat command into the mysql query, but that does not work either. Any other ideas? while (($data = fgetcsv($handle, 1500, ";")) !== FALSE) { $num = count($data); $row++; for ($i=0; $i < $num; $i++) { if($data[0]) { if($data[7] == "NA") { $data[7] = $data[7]; } else { $data[7] = strtotime($data[7]); $data[7] = date("Y-m-d H:i:s", $data[7]); } $data[6] = strtotime($data[6]); $data[8] = strtotime($data[8]); $data[6] = date("Y-m-d H:i:s", $data[6]); $data[8] = date("Y-m-d H:i:s", $data[8]); **$rsntwo = "V2_" . $data[0];** $Query = "INSERT IGNORE INTO $Table (RecordSequenceNumber, RSN2,ConnectionType, SessionID, ReleaseCause, Start_TOD, Answer_TOD, Release_TOD, ReleaseCauseFromStack, BinaryReleaseCause. . .) VALUES ('$data[0]', **'$rsntwo',** '$data[3]', '$data[4]', '$data[5]', '$data[6]', '$data[7]', '$data[8]', '$data[10]', . . .)"; mysql_query($Query) or die(mysql_error()); } } } fclose($handle); unlink("$LocalDirectory/$f"); } } Thanks all! Quote Link to comment Share on other sites More sharing options...
shane2006 Posted July 8, 2007 Author Share Posted July 8, 2007 update - After researching a bit more, I discovered that I needed to add a temp array in order to add in the additional variable. Now if I can just stop it from iterating through each entry 28 or more times, I will have it beat! Here it is with the temp array added: $data[6] = strtotime($data[6]); $data[8] = strtotime($data[8]); $data[6] = date("Y-m-d H:i:s", $data[6]); $data[8] = date("Y-m-d H:i:s", $data[8]); $rsntwo = "V2_" . $data[0]; $temp = array($data[0], $data[3], $data[4], $data[5], $data[6],. . .); $temp[] = $rsntwo; $Query = "INSERT IGNORE INTO $Table (RecordSequenceNumber, RSN2, ConnectionType, SessionID, ReleaseCause, Start_TOD, Answer_TOD, Release_TOD, ReleaseCauseFromStack, . . .) VALUES ('$data[0]', '$rsntwo','$data[3]', '$data[4]', '$data[5]', '$data[6]', '$data[7]', '$data[8]', '$data[10]', '$data[11]', '$data[12]', '$data[13]', '$data[14]', '$data[15]', '$data[16]', '$data[17]', '$data[18]', . . .')"; mysql_query($Query) or die(mysql_error()); } } } fclose($handle); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.