insertAll() not inserting entries into database I've created a database table that I am trying to add information too with a onBeforeSaveElement() hook.

For some reason, although it is telling me that the rows have been added in the $result, there is no records being added. Interestingly, if I run the page an then manually add a record to the database table, the id has been incremented by the amount of rows $result says it has added.. so it seems that the rows are being added then instantly deleted?

Thanks

SQL

CREATE TABLE `craft_lsclearance` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `path` text,
  `cleared` int(11) DEFAULT '0',
  `dateCreated` datetime DEFAULT NULL,
  `dateUpdated` datetime DEFAULT NULL,
  `uid` char(36) DEFAULT '',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=229 DEFAULT CHARSET=latin1;


Function

craft()-&gt;on('elements.onBeforeSaveElement', function(Event $event)
    {
        $element = $event-&gt;params['element'];
        $paths = craft()-&gt;plugin-&gt;getPaths($element);

        foreach ($paths as $path) {
            $newPath = preg_replace('/site:/', '', $path['path'], 1);

            if ($path['locale'] != 'en') {
                $newPath = $path['locale'] . '/' . $newPath;
            }

            $model[] = array(UrlHelper::getSiteUrl($newPath));
        }

        $result = craft()-&gt;db-&gt;createCommand()-&gt;insertAll('lsclearance', array('path'), $model);

        print_r($model);
        echo '&lt;br /&gt; Inserted: ' . $result . 'row(s)';

        exit;

    }
);


Output

Array ( 
  [0] =&gt; Array ( [0] =&gt; http://mydomain.com/ ) 
  [1] =&gt; Array ( [0] =&gt; http://mydomain.com/ ) 
  [2] =&gt; Array ( [0] =&gt; http://mydomain.com/results?q=regatta+ac ) 
  [3] =&gt; Array ( [0] =&gt; http://mydomain.com/watch/regatta-ac-titanium/19225 ) 
  [4] =&gt; Array ( [0] =&gt; http://mydomain.com/mens-watches ) 
  [5] =&gt; Array ( [0] =&gt; http://mydomain.com/mens-watches/p2 ) 
  [6] =&gt; Array ( [0] =&gt; http://mydomain.com/watch/ac-ii/19282 ) 
) 
Inserted: 7 rows
All of the element saving events (like onBeforeElementSave(), onElementSave(), onBeforeSaveEntry()..., etc. are all wrapped in a database transaction (specifically encapsulated in the CDbTransaction class).

When you call exit, you're killing the request and never giving a chance for the transaction to commit to the database.