cakephp 3 Insert with Query Builder update Timestamp fields

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

cakephp 3 Insert with Query Builder update Timestamp fields

Willem
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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.