{"id":74,"date":"2016-09-28T09:38:28","date_gmt":"2016-09-28T00:38:28","guid":{"rendered":"http:\/\/okamurax.com\/?p=74"},"modified":"2017-01-15T20:45:26","modified_gmt":"2017-01-15T11:45:26","slug":"vba%e3%81%a7post-php%e3%81%a7jan%e3%82%92%e7%99%ba%e8%a1%8c%e3%81%97%e3%81%a6mysql%e3%81%ab%e7%99%bb%e9%8c%b2","status":"publish","type":"post","link":"https:\/\/appbay.org\/?p=74","title":{"rendered":"VBA\u3067POST\u3057\u3066PHP\u3067JAN\u3092\u767a\u884c\u3057\u3066MySQL\u306b\u767b\u9332\u3059\u308b"},"content":{"rendered":"<p>\u4ee5\u524d\u3001Web\u3001\u30d0\u30fc\u30b3\u30fc\u30c9\u3092\u4f7f\u3063\u3066\u4f55\u304b\u4f5c\u308d\u3046\u3068\u3057\u305f\u3053\u3068\u304c\u3042\u3063\u305f\u3002<\/p>\n<pre class=\"lang:php decode:true\">&lt;?php\r\n\r\n\/*\r\ncreate database vba_post;\r\nuse vba_post\r\ncreate table post_tb(id int not null primary key auto_increment, value varchar(255));\r\n*\/\r\n\r\nApplication::main();\r\n\r\nclass Application{\r\n\t\r\n\tstatic function con(){\r\n\t\treturn new PDO(\"mysql:dbname=vba_post;host=localhost;charset=utf8\",\"root\",\"123\");\r\n\t}\r\n\t\r\n\tstatic function h($s){\r\n\t\treturn htmlspecialchars ($s,ENT_QUOTES);\r\n\t}\r\n\t\r\n\tstatic function jan($s){\r\n\t\t\r\n\t\t$buf = \"20\" . str_pad($s, 10, \"0\", STR_PAD_LEFT);\r\n\t\t$o = $buf[0] + $buf[2] + $buf[4] + $buf[6] + $buf[8] + $buf[10];\r\n\t\t$e = $buf[1] + $buf[3] + $buf[5] + $buf[7] + $buf[9] + $buf[11];\r\n\t\t$e *= 3;\r\n\t\t$digi = 10 - substr(($e + $o),-1);\r\n\t\tif($digi == 10){ $digi = 0; }\r\n\t\t\r\n\t\treturn $buf . $digi;\r\n\t}\r\n\t\r\n\tstatic function main(){\r\n\t\t\r\n\t\tif(array_key_exists(\"update\",$_POST) &amp;&amp; $_POST[\"update\"] === \"save\"){\r\n\t\t\t\r\n\t\t\t$d = self::con();\r\n\t\t\t$d-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);\r\n\t\t\t\r\n\t\t\ttry{\r\n\t\t\t\t\r\n\t\t\t\t$d-&gt;beginTransaction();\r\n\r\n\t\t\t\t$s = $d-&gt;query(\"show table status like 'post_tb'\"); \r\n\t\t\t\t$id = $s-&gt;fetch();\r\n\r\n\t\t\t\t$p = $d-&gt;prepare(\"insert into post_tb (value) values (:v)\");\r\n\t\t\t\t$p-&gt;execute(array(\r\n\t\t\t\t\t\":v\" =&gt; self::h($_POST['value'])\r\n\t\t\t\t));\r\n\r\n\t\t\t\t$d-&gt;commit();\r\n\t\t\t\techo self::jan($id['Auto_increment']);\r\n\t\t\t\t\r\n\t\t\t}catch(PDOException $e){\r\n\t\t\t\t\r\n\t\t\t\t$d-&gt;rollback();\r\n\t\t\t\techo \"false\";\r\n\t\t\t\t\r\n\t\t\t}\t\r\n\t\t\t\r\n\t\t}\r\n\t\t\r\n\t}\r\n\t\r\n}\r\n\r\n<\/pre>\n<p>VBA\u3067POST\u3059\u308b<\/p>\n<pre class=\"lang:vb decode:true\">Private Sub CommandButton1_Click()\r\n\r\nDim url As String\r\nurl = \"http:\/\/192.168.1.4\/request\/index.php\"\r\n\r\nDim xmlhttp As Object\r\nSet xmlhttp = CreateObject(\"msxml2.xmlhttp\")\r\n\r\nDim paramStr As String\r\nDim retCd As String\r\n\r\nOn Error GoTo e\r\n\r\nFor i = 2 To ActiveSheet.UsedRange.Rows.Count\r\n\r\n    paramStr = \"&amp;update=save&amp;value=\" &amp; Cells(i, 1).Value\r\n    xmlhttp.Open \"POST\", url, False\r\n    xmlhttp.setRequestHeader \"Content-Type\", \"application\/x-www-form-urlencoded\"\r\n    xmlhttp.send (paramStr)\r\n    \r\n    Cells(i, 2).Value = xmlhttp.Status\r\n    Cells(i, 3).Value = xmlhttp.responseText\r\n\r\nNext i\r\n\r\nSet xmlhttp = Nothing\r\nMsgBox \"done!\"\r\n\r\nExit Sub\r\n\r\ne:\r\n\r\n    Set xmlhttp = Nothing\r\n    MsgBox i &amp; \"\u884c\u76ee\u3067\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3057\u307e\u3057\u305f\u3002\"\r\n\r\nEnd Sub\r\n<\/pre>\n<p>\u304a\u307e\u3051<\/p>\n<pre class=\"lang:vb decode:true \">Sub test()\r\n\r\nSet xh = CreateObject(\"msxml2.xmlhttp\")\r\nSet sc = CreateObject(\"ScriptControl\")\r\nsc.Language = \"JScript\"\r\nsc.AddCode \"function jsonParse(s) { return eval('(' + s + ')'); }\"\r\n\r\nxh.Open \"POST\", \"http:\/\/xxx.com\/index.php\", False\r\nxh.setRequestHeader \"Content-Type\", \"application\/x-www-form-urlencoded\"\r\nxh.send (\"&amp;save=do\")\r\n\r\nIf xh.Status = 200 Then\r\n\r\n    Set js = sc.CodeObject.jsonParse(xh.ResponseText)\r\n    MsgBox js.Name\r\n    \r\nEnd If\r\n\r\nEnd Sub\r\n\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u4ee5\u524d\u3001Web\u3001\u30d0\u30fc\u30b3\u30fc\u30c9\u3092\u4f7f\u3063\u3066\u4f55\u304b\u4f5c\u308d\u3046\u3068\u3057\u305f\u3053\u3068\u304c\u3042\u3063\u305f\u3002 &lt;?php \/* create database vba_post; use vba_post create table post_tb(id int &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/appbay.org\/?p=74\" class=\"more-link\"><span class=\"screen-reader-text\">&#8220;VBA\u3067POST\u3057\u3066PHP\u3067JAN\u3092\u767a\u884c\u3057\u3066MySQL\u306b\u767b\u9332\u3059\u308b&#8221; \u306e<\/span>\u7d9a\u304d\u3092\u8aad\u3080<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[3,5],"class_list":["post-74","post","type-post","status-publish","format-standard","hentry","category-1","tag-php","tag-vba"],"_links":{"self":[{"href":"https:\/\/appbay.org\/index.php?rest_route=\/wp\/v2\/posts\/74","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/appbay.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/appbay.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/appbay.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/appbay.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=74"}],"version-history":[{"count":8,"href":"https:\/\/appbay.org\/index.php?rest_route=\/wp\/v2\/posts\/74\/revisions"}],"predecessor-version":[{"id":130,"href":"https:\/\/appbay.org\/index.php?rest_route=\/wp\/v2\/posts\/74\/revisions\/130"}],"wp:attachment":[{"href":"https:\/\/appbay.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=74"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/appbay.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=74"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/appbay.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=74"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}