{"id":3747,"date":"2020-09-25T01:32:56","date_gmt":"2020-09-24T16:32:56","guid":{"rendered":"https:\/\/okamurax.com\/?p=3747"},"modified":"2020-09-25T01:32:56","modified_gmt":"2020-09-24T16:32:56","slug":"python-%e3%83%87%e3%83%bc%e3%82%bf%e3%83%99%e3%83%bc%e3%82%b9%e5%9f%ba%e6%9c%ac","status":"publish","type":"post","link":"https:\/\/appbay.org\/?p=3747","title":{"rendered":"Python \u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u57fa\u672c"},"content":{"rendered":"<pre class=\"lang:python decode:true \"># SQLite --------------------------------------------------------\r\n\r\nimport sqlite3\r\n\r\ncon = sqlite3.connect(\"dat.sqlite\")\r\n# sqlite3.connect(\":memory:\")\r\n\r\ncur = con.cursor()\r\n\r\ncur.execute(\"create table if not exists tbl (id integer primary key, name text)\") # int \u3060\u3068\u81ea\u52d5\u63a1\u756a\u3057\u306a\u3044\r\ncon.commit()\r\n\r\ncur.execute(\"insert into tbl (name) values ('taro')\")\r\ncon.commit()\r\n\r\ncur.execute(\"select * from tbl\")\r\nprint(cur.fetchall())\r\n\r\ncur.close()\r\ncon.close()\r\n\r\n# MySQL --------------------------------------------------------\r\n\r\n# pip install mysql-connector-python\r\n\r\nimport mysql.connector\r\n\r\n# DB\u3092\u6307\u5b9a\u3057\u306a\u3044\u5834\u5408\r\ncon = mysql.connector.connect(host=\"localhost\",user=\"root\",password=\"1234\")\r\ncur = con.cursor()\r\ncur.execute(\"create database if not exists test_db\")\r\ncon.commit()\r\n\r\ncur.close()\r\ncon.close()\r\n\r\n# DB\u3092\u6307\u5b9a\r\ncon = mysql.connector.connect(host=\"localhost\",user=\"root\",password=\"1234\",database=\"test_db\")\r\ncur = con.cursor()\r\ncur.execute(\"create table if not exists tbl (id int not null auto_increment, name varchar(255) not null, primary key(id))\")\r\ncon.commit()\r\n\r\ncur.execute(\"insert into tbl (name) values ('taro')\")\r\ncon.commit()\r\n\r\ncur.execute(\"select * from tbl\")\r\nfor r in cur:\r\n    print(r)\r\n\r\ncur.close()\r\ncon.close()\r\n<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p># SQLite &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211; import sqlite3 con = sqlite3.connect(&#8220;dat.sq &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/appbay.org\/?p=3747\" class=\"more-link\"><span class=\"screen-reader-text\">&#8220;Python \u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u57fa\u672c&#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":[154],"class_list":["post-3747","post","type-post","status-publish","format-standard","hentry","category-1","tag-python"],"_links":{"self":[{"href":"https:\/\/appbay.org\/index.php?rest_route=\/wp\/v2\/posts\/3747","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=3747"}],"version-history":[{"count":1,"href":"https:\/\/appbay.org\/index.php?rest_route=\/wp\/v2\/posts\/3747\/revisions"}],"predecessor-version":[{"id":3748,"href":"https:\/\/appbay.org\/index.php?rest_route=\/wp\/v2\/posts\/3747\/revisions\/3748"}],"wp:attachment":[{"href":"https:\/\/appbay.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3747"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/appbay.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3747"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/appbay.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3747"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}