{"id":409,"date":"2019-11-13T11:02:29","date_gmt":"2019-11-13T18:02:29","guid":{"rendered":"https:\/\/www.great-white-software.com\/blog\/?p=409"},"modified":"2019-11-19T09:49:24","modified_gmt":"2019-11-19T16:49:24","slug":"prepared-statements","status":"publish","type":"post","link":"https:\/\/www.great-white-software.com\/blog\/2019\/11\/13\/prepared-statements\/","title":{"rendered":"Prepared Statements"},"content":{"rendered":"\n<p>Often you&#8217;ll hear people say you should use prepared statements to avoid <a href=\"https:\/\/en.wikipedia.org\/wiki\/SQL_injection\">sql injection<\/a> issues. They&#8217;re not wrong. But there can be other reasons to use them.<\/p>\n\n\n\n<p>In some db&#8217;s when you create a prepared statement and use it over &amp; over you can avoid a fair amount of a speed hit.<\/p>\n\n\n\n<p>When you initially create a prepared statement many db engines will actually do some work to figure out what the optimal mechanism, or query plan, is to access the data in a table.<\/p>\n\n\n\n<p>And by reusing this over &amp; over you can avoid that computation to determine that optimal query plan.<\/p>\n\n\n\n<p>Not ALL db&#8217;s do this, and in some it wont matter if you use a prepared statement because they simply recompute the query plan every time anyways.<\/p>\n\n\n\n<p>But, even if the db engine DOES recompute the query plan over &amp; over you still get all the benefits of avoiding sql injections issues by using them.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>I&#8217;d say they definitely fall into the category of &#8220;best practice&#8221;.<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Often you&#8217;ll hear people say you should use prepared statements to avoid sql injection issues. They&#8217;re not wrong. But there can be other reasons to use them. In some db&#8217;s when you create a prepared statement and use it over &amp; over you can avoid a fair amount of a speed hit. When you initially &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.great-white-software.com\/blog\/2019\/11\/13\/prepared-statements\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Prepared Statements&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1],"tags":[6],"class_list":["post-409","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-tips"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/posts\/409","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/comments?post=409"}],"version-history":[{"count":3,"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/posts\/409\/revisions"}],"predecessor-version":[{"id":424,"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/posts\/409\/revisions\/424"}],"wp:attachment":[{"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/media?parent=409"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/categories?post=409"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/tags?post=409"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}