{"id":806,"date":"2021-12-12T03:15:00","date_gmt":"2021-12-12T03:15:00","guid":{"rendered":"https:\/\/262235.xyz\/?p=806"},"modified":"2021-12-12T03:15:00","modified_gmt":"2021-12-12T03:15:00","slug":"806","status":"publish","type":"post","link":"https:\/\/lyvba.com\/index.php\/2021\/12\/12\/806\/","title":{"rendered":"\u4f7f\u7528sql\u6570\u636e\u8868\u4fdd\u5b58\u811a\u672c\u4ee3\u7801\u6587\u4ef6\uff0cPython\u811a\u672c\u4ece\u6570\u636e\u5e93\u91cc\u4e0a\u4f20\u548c\u4e0b\u8f7d\u4ee3\u7801\u6587\u4ef6"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/lyvba.com\/wp-content\/uploads\/2021\/12\/1283040383.png\" alt=\"sql\u8868\u683c\" title=\"sql\u8868\u683c\"><br \/>\u5b66\u4e60Python\u811a\u672c\u548cSQL\u6570\u636e\u5e93\u4f7f\u7528\uff0c\u4e3a\u4e86\u4fdd\u6301\u591a\u8bbe\u5907\u4ee3\u7801\u7684\u7248\u672c\u540c\u6b65\uff0c\u6298\u817e\u628a\u811a\u672c\u4ee3\u7801\u4fdd\u5b58\u5230SQL\u6570\u636e\u8868\u4e2d\u3002<br \/>\u65b9\u4fbf\u4e00\u8d77\u5907\u4efd\uff0c\u7528\u5230\u65b9\u4fbf\u66f4\u65b0\uff0c\u4e5f\u53ef\u4ee5\u518d\u5199\u4e2a\u6279\u91cf\u63d2\u5165\u6587\u4ef6\u548c\u66f4\u65b0\u6587\u4ef6\u811a\u672c\uff0c\u7f51\u9875\u7aef\u8bfb\u53d6\u4f7f\u7528\u3002<\/p>\n<h2>\u53ef\u4ee5\u4f7f\u7528\u56fe\u5f62\u5de5\u5177\u8f6f\u4ef6\uff0c\u8fde\u6570\u636e\u5e93\u5efa\u7acb\u8868<\/h2>\n<ul>\n<li>\n<p>\u8868 vps2022.text \u7ed3\u6784<\/p>\n<pre><code>CREATE TABLE IF NOT EXISTS \"text\" (\n\"name\" text,\n\"text\" text\n) ENGINE=InnoDB DEFAULT CHARSET=utf8;<\/code><\/pre>\n<\/li>\n<\/ul>\n<h2>\u83b7\u53d6sql\u6570\u636e\u8868 text \u4e2d\u6240\u6709\u811a\u672c\u6587\u4ef6\u7684\u4ee3\u7801<\/h2>\n<p><img decoding=\"async\" src=\"https:\/\/lyvba.com\/wp-content\/uploads\/2021\/12\/2063028572.png\" alt=\"get.PNG\" title=\"get.PNG\"><\/p>\n<h3><code>getsh.py<\/code><\/h3>\n<pre><code>import mysql.connector\nconn = mysql.connector.connect(\n  host=\"127.0.0.1\",\n  user=\"user\",\n  passwd=\"passwd\"  )\nc = conn.cursor()\nc.execute(\"USE vps2022\")\n\nsql = 'SELECT * FROM text ORDER BY name'\nc.execute(sql)\ntext = c.fetchall()\n\ndef makefile(file, str):\n  f = open(file, 'w')\n  f.write(str); f.close()\n\nfor i in range(len(text)):\n  file=text[i][0]\n  file_str = text[i][3]\n  makefile(file, file_str)\n  print(file, \"    \u4fdd\u5b58\u5b8c\u6210!\")\n\nconn.close()<\/code><\/pre>\n<h2>\u9009\u62e9\u4e0b\u8f7d\u4e00\u4e2a\u6587\u4ef6 <code>getfile.py<\/code><\/h2>\n<p><img decoding=\"async\" src=\"https:\/\/lyvba.com\/wp-content\/uploads\/2021\/12\/516251946.png\" alt=\"getfile.PNG\" title=\"getfile.PNG\"><\/p>\n<pre><code>import mysql.connector\nconn = mysql.connector.connect(\n    host=\"127.0.0.1\",\n    user=\"user\",  passwd=\"pswd\",\n    database=\"vps2022\",  buffered = True  )\nc = conn.cursor()\n\nsql = 'SELECT name FROM text'\nc.execute(sql)\nnames = c.fetchall()\n\n# \u663e\u793a\u6240\u6709\u6587\u4ef6\u540d\uff0c\u4ee5\u4f9b\u4e0b\u8f7d\nfor i in range(len(names)):\n    print(names[i][0], end='  ')\n\nprint('\n:: \u9009\u62e9\u4e00\u4e2a\u6587\u4ef6\u4e0b\u8f7d\uff0c\u8f93\u5165\u6587\u4ef6\u540d: ', end='')\nname = input().strip()\n\nsql = 'SELECT * FROM text WHERE name=\"' + name +'\"'\nc.execute(sql)\ntext = c.fetchall()\n\ndef makefile(file, str):\n    f = open(file, 'w')\n    f.write(str); f.close()\n\nfor i in range(len(text)):\n    file=text[i][0]\n    file_str = text[i][5]\n    makefile(file, file_str)\n    print(file, \"    \u4fdd\u5b58\u5b8c\u6210!\")\n\nconn.close()<\/code><\/pre>\n<h2>\u4f7f\u7528 <code>addfile.py<\/code> \u53ef\u4ee5\u6279\u91cf\u4e0a\u4f20\u6587\u4ef6\u5230\u6570\u636e\u5e93\u4e2d<\/h2>\n<p><img decoding=\"async\" src=\"https:\/\/lyvba.com\/wp-content\/uploads\/2021\/12\/4190129443.png\" alt=\"addfile.PNG\" title=\"addfile.PNG\"><\/p>\n<pre><code>import sys, glob\nimport mysql.connector\nconn = mysql.connector.connect(\n    host=\"127.0.0.1\",\n    user=\"user\",  passwd=\"passwd\",\n    database=\"vps2022\",  buffered = True  )\nc = conn.cursor()\n\nfiles = []\nfor f in sys.argv[1:]:\n    files = files + glob.glob(f)\n\ndef readfile(file):\n    f = open(file, 'r')\n    str = f.read(); f.close()\n    return str\n\nfor file in files:\n    file_str = readfile(file)\n    row =(file, file_str)\n\n    c.execute(\"DELETE FROM text WHERE name=%s \", (file,) )\n    c.execute('INSERT INTO text VALUES (%s,%s)', row)\n    print(\"FontName: \" + file + \"   ....OK\")\n\nconn.commit()\nconn.close()<\/code><\/pre>\n<h2>\u76f8\u5173: \u4f7f\u7528php\u83b7\u53d6\u6587\u4ef6\u540d\u548c\u6587\u4ef6<\/h2>\n<p><img decoding=\"async\" src=\"https:\/\/lyvba.com\/wp-content\/uploads\/2021\/12\/926986731.png\" alt=\"php.png\" title=\"php.png\"><\/p>\n<pre><code>&lt;?php\nmysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);\n$mysqli = mysqli_connect(\"18.18.18.18\", \"root\", \"\u5b9e\u9645\u5bc6\u7801\", \"vps2022\",\"53306\");\n\n$result = mysqli_query($mysqli, \"SELECT name FROM text\");\n\/\/ $result = mysqli_query($mysqli, \"SELECT * FROM text WHERE name = 'addfile.py'\");\n\n$rows = mysqli_fetch_all($result, MYSQLI_ASSOC);   \/\/ MYSQLI_ASSOC, MYSQLI_NUM, or MYSQLI_BOTH\nforeach ($rows as $row) {\n    printf(\"%s\n\", $row[\"name\"]);\n    \/\/ printf(\"%s (%s)\n\", $row[\"name\"], $row[\"text\"]);\n}\n\nvar_dump($rows);\n\/**  MYSQLI_ASSOC\narray(11) {\n    [0]=&gt;\n    array(1) {\n      [\"name\"]=&gt;\n      string(10) \"addfile.py\"\n **  MYSQLI_NUM\narray(11) {\n  [0]=&gt;\n  array(1) {\n    [0]=&gt;\n    string(10) \"addfile.py\"\n *\/<\/code><\/pre>\n<ul>\n<li>MYSQLI_ASSOC, MYSQLI_NUM, or MYSQLI_BOTH \u53ef\u9009\u53c2\u6570\u662f\u4e00\u4e2a\u5e38\u91cf\uff0c\u6307\u793a\u5e94\u4ece\u5f53\u524d\u884c\u6570\u636e\u751f\u6210\u4ec0\u4e48\u7c7b\u578b\u7684\u6570\u7ec4\u3002<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u5b66\u4e60Python\u811a\u672c\u548cSQL\u6570\u636e\u5e93\u4f7f\u7528\uff0c\u4e3a\u4e86\u4fdd\u6301\u591a\u8bbe\u5907\u4ee3\u7801\u7684\u7248\u672c\u540c\u6b65\uff0c\u6298\u817e\u628a\u811a\u672c\u4ee3\u7801\u4fdd\u5b58\u5230SQL\u6570\u636e [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[45,59],"class_list":["post-806","post","type-post","status-publish","format-standard","hentry","category-learn","tag-python","tag-sql"],"_links":{"self":[{"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/posts\/806","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/comments?post=806"}],"version-history":[{"count":0,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/posts\/806\/revisions"}],"wp:attachment":[{"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/media?parent=806"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/categories?post=806"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/tags?post=806"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}