{"id":2612,"date":"2020-03-31T16:11:07","date_gmt":"2020-03-31T15:11:07","guid":{"rendered":"https:\/\/ibex.tech\/cloud\/?p=2612"},"modified":"2023-03-19T16:39:19","modified_gmt":"2023-03-19T16:39:19","slug":"insert-2","status":"publish","type":"post","link":"https:\/\/ibex.tech\/cloud\/wordpress\/database\/queries-database\/insert-2","title":{"rendered":"INSERT"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>  $sql = $wpdb-&gt;prepare(\"INSERT INTO {$wpdb-&gt;prefix}tbl_my_table\n            ( \n              user_id,\n              CreatedOn\n            ) VALUES (\n              %d,\n              Now()\n            )\", $user_id);\n  if (current_user_can('administrator'))\n    $wpdb-&gt;show_errors();\n  $wpdb-&gt;query($sql);<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Was INSERT sucessful?<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>  if ($wpdb->query($sql) === False)   \/\/Returns number of rows inserted, or False on error\n  {\n    \/\/INSERT failed\n  }<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Get Auto ID Of New Record<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>  $Result = $wpdb->query($sql);\n  if ($Result == True)\n    return($wpdb->insert_id);\n  else\n    return(False);<\/code><\/pre>\n\n\n\n<p>The insert_id() function returns the auto generated id used in the latest querywith a column having the AUTO_INCREMENT attribute.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Was INSERT sucessful? Get Auto ID Of New Record The insert_id() function returns the auto generated id used in the latest querywith a column having the AUTO_INCREMENT attribute.<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[169],"tags":[],"class_list":["post-2612","post","type-post","status-publish","format-standard","hentry","category-queries-database"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/2612","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/comments?post=2612"}],"version-history":[{"count":3,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/2612\/revisions"}],"predecessor-version":[{"id":4489,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/2612\/revisions\/4489"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/media?parent=2612"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/categories?post=2612"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/tags?post=2612"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}