{"id":465,"date":"2021-12-02T13:19:33","date_gmt":"2021-12-02T13:19:33","guid":{"rendered":"http:\/\/tietokanta.dy.fi:8243\/mikko\/wordpress\/?p=465"},"modified":"2021-12-02T13:19:33","modified_gmt":"2021-12-02T13:19:33","slug":"auto_increment","status":"publish","type":"post","link":"http:\/\/tietokanta.dy.fi:8243\/mikko\/wordpress\/index.php\/2021\/12\/02\/auto_increment\/","title":{"rendered":"AUTO_INCREMENT"},"content":{"rendered":"\n<p>When using AUTO_INCREMENT, you cannot know what value has been given to a column before a row is inserted. Instead, if you need to know it, you must ask MySQL afterward using the mysql_insert_id function. This need is common: for instance, when you process a purchase, you might insert a new customer into a Customers table and then refer to the newly created CustId when inserting a purchase into the Purchases table.<\/p>\n\n\n\n<p>Using AUTO_INCREMENT is recommended instead of selecting the<br>highest ID in the id column and incrementing it by one, because<br>concurrent queries could change the values in that column after the<br>highest value has been fetched and before the calculated value is<br>stored.<\/p>\n\n\n\n<p><a href=\"http:\/\/tietokanta.dy.fi:8243\/mikko\/wordpress\/data\/auto_increment.txt\">Adding data to the devices table and reporting the insert ID<\/a><\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>When using AUTO_INCREMENT, you cannot know what value has been given to a column before a row is inserted. Instead, if you need to know it, you must ask MySQL afterward using the mysql_insert_id function. This need is common: for instance, when you process a purchase, you might insert a new customer into a Customers &hellip; <a href=\"http:\/\/tietokanta.dy.fi:8243\/mikko\/wordpress\/index.php\/2021\/12\/02\/auto_increment\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">AUTO_INCREMENT<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"http:\/\/tietokanta.dy.fi:8243\/mikko\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/465"}],"collection":[{"href":"http:\/\/tietokanta.dy.fi:8243\/mikko\/wordpress\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/tietokanta.dy.fi:8243\/mikko\/wordpress\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/tietokanta.dy.fi:8243\/mikko\/wordpress\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/tietokanta.dy.fi:8243\/mikko\/wordpress\/index.php\/wp-json\/wp\/v2\/comments?post=465"}],"version-history":[{"count":1,"href":"http:\/\/tietokanta.dy.fi:8243\/mikko\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/465\/revisions"}],"predecessor-version":[{"id":466,"href":"http:\/\/tietokanta.dy.fi:8243\/mikko\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/465\/revisions\/466"}],"wp:attachment":[{"href":"http:\/\/tietokanta.dy.fi:8243\/mikko\/wordpress\/index.php\/wp-json\/wp\/v2\/media?parent=465"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/tietokanta.dy.fi:8243\/mikko\/wordpress\/index.php\/wp-json\/wp\/v2\/categories?post=465"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/tietokanta.dy.fi:8243\/mikko\/wordpress\/index.php\/wp-json\/wp\/v2\/tags?post=465"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}