{"id":50,"date":"2022-03-07T23:04:52","date_gmt":"2022-03-07T15:04:52","guid":{"rendered":"https:\/\/wpblog.chanyu.info\/?p=50"},"modified":"2022-03-07T23:04:52","modified_gmt":"2022-03-07T15:04:52","slug":"%e8%b3%87%e5%b7%a5%e7%ad%86%e8%a8%98php-php-pdo-fetchall-select%e5%8f%96%e5%be%97%e8%b3%87%e6%96%99","status":"publish","type":"post","link":"https:\/\/wpblog.chanyu.info\/?p=50","title":{"rendered":"[\u8cc7\u5de5\u7b46\u8a18@PHP] PHP PDO fetchAll() SELECT\u53d6\u5f97\u8cc7\u6599"},"content":{"rendered":"<p>\u4ee5\u4e0b\u662f\u6211\u500b\u4eba\u7684PHP\u7b46\u8a18<\/p>\n<p>\u6b64\u529f\u80fd\u70baPHP PDO fetchAll() SELECT\u53d6\u5f97\u8cc7\u6599\uff0c\u5982\u4f55\u9032\u884c\u8b80\u53d6\u7684\u7bc4\u4f8b\u3002<\/p>\n<pre><code>try\n    {\n        $sql = \"SELECT * FROM testdata01 WHERE timestamp >= '$startTime' AND timestamp <= '$endTime';\"; \n        $query = $PDO -> query($sql);\n        $sql_data = $query -> fetchAll();\n\n        foreach($sql_data as $sql_data)\n        {\n            $sql_timestamp[] = $sql_data[0];\n            $sql_time[] = $sql_data[1];\n            \/\/ \u9010\u7b46\u8b80\u53d6SQL\u8cc7\u6599\n        }\n\n        echo json_encode(array(\n            \"Status\" => \"AJAX Success.\",\n            \"startTime\" => $startTime,\n            \/\/ JSON\u56de\u50b3\n        ), JSON_UNESCAPED_UNICODE);\n    }\n    catch (PDOException $e) \n    {\n        \/\/ echo \"[PDO\u8cc7\u6599\u5eab\u9023\u7dda\u932f\u8aa4] Connection failed: \" . $e->getMessage();\n        echo json_encode(array(\n            \"status\" => \"ERROR_BY_PHP_OR_PDO\",\n            \"comment\" => \"PHP PDO \u6307\u4ee4\u932f\u8aa4\u5931\u6557\u3002\",\n        ), JSON_UNESCAPED_UNICODE);\n        return;\n    }<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u6b64\u529f\u80fd\u70baPHP PDO fetchAll() SELECT\u53d6\u5f97\u8cc7\u6599\uff0c\u5982\u4f55\u9032\u884c\u8b80\u53d6\u7684\u7bc4\u4f8b\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[37],"tags":[41,40,39,42,38],"class_list":["post-50","post","type-post","status-publish","format-standard","hentry","category-37","tag-fetchall","tag-pdo","tag-php","tag-select","tag-38"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/wpblog.chanyu.info\/index.php?rest_route=\/wp\/v2\/posts\/50","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wpblog.chanyu.info\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wpblog.chanyu.info\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wpblog.chanyu.info\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wpblog.chanyu.info\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=50"}],"version-history":[{"count":1,"href":"https:\/\/wpblog.chanyu.info\/index.php?rest_route=\/wp\/v2\/posts\/50\/revisions"}],"predecessor-version":[{"id":51,"href":"https:\/\/wpblog.chanyu.info\/index.php?rest_route=\/wp\/v2\/posts\/50\/revisions\/51"}],"wp:attachment":[{"href":"https:\/\/wpblog.chanyu.info\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=50"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wpblog.chanyu.info\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=50"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wpblog.chanyu.info\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=50"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}