Tuesday, December 22, 2015

cakephp 3 Insert with Query Builder update Timestamp fields

Using the query builder to insert multiple rows of data the timestamp fields are not automatically updated, is this correct? 

so i changed my code a little to add the fields myself. Not sure if this is the best way or am i missing something


$oQuery = $this->query();

if (($handle = fopen($tmpFilename, "r")) !== FALSE) {
while (($data = fgetcsv($handle, 0, ",")) !== FALSE) {
$num = count($data);
if ($linenumber == 1) {
for ($c = 0; $c < $num; $c++) {
$columnnames[] = $data[$c];
}
} else {
for ($c = 0; $c < $num; $c++) {
$line['csv_file_id'] = $csvFileId;
$line['linenumber'] = $linenumber;
$line['columnname'] = $columnnames[$c];
$line['columndata'] = $data[$c];
$line['created'] = date('Y-m-d h:m:s');
$line['modified'] = date('Y-m-d h:m:s');

$oQuery->insert(['csv_file_id', 'linenumber', 'columnname', 'columndata','created','modified'])
->values($line);
}
}
$linenumber++;
}
fclose($handle);

$oQuery->execute();

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at https://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.

No comments: