PDO查询中的fetch()和fetchAll()有什么区别?

时间:2019-03-16 12:36:54

标签: mysql pdo

我对在PDO语句中使用setStateimport React, { createContext, useState } from "react"; import jwtDecode from "jwt-decode"; const localStorageKey = "ar_refresh_token"; export const AuthContext = createContext(); export function AuthProvider({ tokenUrl, registerUrl, refreshUrl, children }) { const [refreshToken, setRefreshToken] = useState( window.localStorage.getItem(localStorageKey) ); const [accessToken, setAccessToken] = useState(); const login = async (userId, password) => { const response = await fetch(tokenUrl, { method: "POST", mode: "cors", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ userId, password }) }); if (response.status === 201) { const token = await response.text(); setRefreshToken(token); window.localStorage.setItem(localStorageKey, token); await refresh(); } }; const refresh = async () => { const response = await fetch(refreshUrl, { method: "POST", mode: "cors", headers: { "Content-Type": "application/json", Authorization: `JWT ${refreshToken}` } }); if (response.status === 201) { const token = await response.text(); setAccessToken(token); } }; return ( <AuthContext.Provider value={{ refreshToken, accessToken, login, refresh }} > {children} </AuthContext.Provider> ); } 感到困惑。我仔细阅读了fetch()手册,这使它更加混乱。甚至经历了
中提供的建议 fetchAll。如果有人可以帮助我以简单的方式理解它,那就太好了。

例如

php.net

1 个答案:

答案 0 :(得分:1)

文档说:

  

PDOStatement::fetch   —从结果集中获取下一行

     

PDOStatement::fetchAll —返回包含所有结果集行的数组

对我来说似乎不太混乱。