{"id":60,"date":"2012-04-05T13:02:33","date_gmt":"2012-04-05T18:02:33","guid":{"rendered":"http:\/\/blogs.law.harvard.edu\/acts\/?p=60"},"modified":"2012-04-09T09:28:41","modified_gmt":"2012-04-09T14:28:41","slug":"yii-handling-getlastinsertid-with-oracle","status":"publish","type":"post","link":"https:\/\/archive.blogs.harvard.edu\/acts\/2012\/04\/05\/yii-handling-getlastinsertid-with-oracle\/","title":{"rendered":"Yii handling &#8220;getLastInsertId&#8221; with Oracle"},"content":{"rendered":"<p>With MySQL or SQLite, when you insert something with an auto_increment field, it will automatically deal with the ActiveRecord by putting the last inserted id into $model-&gt;id.  <a href=\"http:\/\/blogs.law.harvard.edu\/acts\/2012\/04\/04\/yii-migrations-dealing-with-auto_increment-for-oracle-and-mysql\/\" title=\"Yii Migrations: Dealing with auto_increment for Oracle and MySQL\">Because Oracle needs sequences and triggers<\/a> to deal with that, neither the PDO driver nor the Yii PDO code felt it necessary to deal with that.  Most people are probably fine with commiting to a database and throwing in Oracle specific sequence_name.nextval.  <\/p>\n<p>I just added <a href=\"https:\/\/gist.github.com\/2312855\" title=\"QActiveRecord\">a class in the models to extend CActiveRecord<\/a>.  The only thing you need to do with this is have your model extend this instead of CActiveRecord and add the variable schemaName to the model:<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\nclass User extends QActiveRecord\r\n{\r\n\tpublic $sequenceName = &#039;USERS_SEQ&#039;;\t\r\n...\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>With MySQL or SQLite, when you insert something with an auto_increment field, it will automatically deal with the ActiveRecord by putting the last inserted id into $model-&gt;id. Because Oracle needs sequences and triggers to deal with that, neither the PDO driver nor the Yii PDO code felt it necessary to deal with that. Most people [&hellip;]<\/p>\n","protected":false},"author":4571,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[63924,1841,63942,3163,63928,63937],"tags":[63949,63952,4034,63953,63930,63943],"class_list":["post-60","post","type-post","status-publish","format-standard","hentry","category-atg","category-databases","category-oracle-databases","category-php","category-quizmo-atg","category-yii","tag-auto_increment","tag-getlastinsertid","tag-oracle","tag-pdo","tag-php-2","tag-yii-2"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/archive.blogs.harvard.edu\/acts\/wp-json\/wp\/v2\/posts\/60","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/archive.blogs.harvard.edu\/acts\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/archive.blogs.harvard.edu\/acts\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/archive.blogs.harvard.edu\/acts\/wp-json\/wp\/v2\/users\/4571"}],"replies":[{"embeddable":true,"href":"https:\/\/archive.blogs.harvard.edu\/acts\/wp-json\/wp\/v2\/comments?post=60"}],"version-history":[{"count":4,"href":"https:\/\/archive.blogs.harvard.edu\/acts\/wp-json\/wp\/v2\/posts\/60\/revisions"}],"predecessor-version":[{"id":68,"href":"https:\/\/archive.blogs.harvard.edu\/acts\/wp-json\/wp\/v2\/posts\/60\/revisions\/68"}],"wp:attachment":[{"href":"https:\/\/archive.blogs.harvard.edu\/acts\/wp-json\/wp\/v2\/media?parent=60"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/archive.blogs.harvard.edu\/acts\/wp-json\/wp\/v2\/categories?post=60"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/archive.blogs.harvard.edu\/acts\/wp-json\/wp\/v2\/tags?post=60"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}