{"id":5872,"date":"2020-07-04T12:01:58","date_gmt":"2020-07-04T03:01:58","guid":{"rendered":"https:\/\/nsme.red\/wp\/?p=5872"},"modified":"2024-07-02T19:01:00","modified_gmt":"2024-07-02T10:01:00","slug":"insert","status":"publish","type":"post","link":"https:\/\/core.nsme.net\/notes\/php\/pdo\/5872\/","title":{"rendered":"INSERT"},"content":{"rendered":"\n<p>\u3000\u53c2\u8003\u3000<a href=\"http:\/\/www.phpbook.jp\/tutorial\/pdo\/index9.html\">http:\/\/www.phpbook.jp\/tutorial\/pdo\/index9.html<\/a><\/p>\n\n\n\n<p>&nbsp;\u300cprepare\u300d\u30e1\u30bd\u30c3\u30c9\u3067SQL\u6587\u3092\u4f5c\u6210\u3057\u300cexecute\u300d\u30e1\u30bd\u30c3\u30c9\u3067SQL\u6587\u3092\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3078\u767a\u884c<\/p>\n\n\n\n<p>$sql = &#8216;insert into shouhin (id, name) values (?, ?)&#8217;;<br>$stmt = $dbh-&gt;prepare($sql);<br>$flag = $stmt-&gt;execute(array(6, &#8216;\u6247\u98a8\u6a5f&#8217;));<\/p>\n\n\n\n<p>if ($flag){<br>print(&#8216;\u30c7\u30fc\u30bf\u306e\u8ffd\u52a0\u306b\u6210\u529f\u3057\u307e\u3057\u305f&lt;br&gt;&#8217;);<br>}else{<br>print(&#8216;\u30c7\u30fc\u30bf\u306e\u8ffd\u52a0\u306b\u5931\u6557\u3057\u307e\u3057\u305f&lt;br&gt;&#8217;);<br>}<\/p>\n\n\n\n<h3 class=\"wp-block-heading has-cyan-bluish-gray-background-color has-background\"><strong>\u6700\u5f8c\u306binsert\u3057\u305fID\u3092\u53d6\u5f97<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>$id = $dbh->lastInsertId();<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u3000\u53c2\u8003\u3000http:\/\/www.phpbook.jp\/tutorial\/pdo\/index9.html &nbsp;\u300cprepare\u300d\u30e1\u30bd\u30c3\u30c9\u3067SQL\u6587\u3092\u4f5c\u6210\u3057\u300cexecute\u300d\u30e1\u30bd\u30c3\u30c9\u3067SQL\u6587\u3092\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3078\u767a\u884c $s [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[25],"tags":[],"class_list":["post-5872","post","type-post","status-publish","format-standard","hentry","category-pdo"],"acf":[],"_links":{"self":[{"href":"https:\/\/core.nsme.net\/notes\/wp-json\/wp\/v2\/posts\/5872","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/core.nsme.net\/notes\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/core.nsme.net\/notes\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/core.nsme.net\/notes\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/core.nsme.net\/notes\/wp-json\/wp\/v2\/comments?post=5872"}],"version-history":[{"count":3,"href":"https:\/\/core.nsme.net\/notes\/wp-json\/wp\/v2\/posts\/5872\/revisions"}],"predecessor-version":[{"id":6268,"href":"https:\/\/core.nsme.net\/notes\/wp-json\/wp\/v2\/posts\/5872\/revisions\/6268"}],"wp:attachment":[{"href":"https:\/\/core.nsme.net\/notes\/wp-json\/wp\/v2\/media?parent=5872"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/core.nsme.net\/notes\/wp-json\/wp\/v2\/categories?post=5872"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/core.nsme.net\/notes\/wp-json\/wp\/v2\/tags?post=5872"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}