twitter ユーザ情報のDB格納とログイン処理
#10 ユーザー情報を格納してみよう (2)
http://dotinstall.com/lessons/tw_connect_php_v2/21910
を参考に
ユーザ情報のDB格納とログイン処理を実装
SQL文は前回作成しているので
1 2 3 4 5 6 7 8 9 | $stmt = $dbh ->prepare( $sql ); prepare() のパラメータを $params = array ( ":tw_user_id" => $me ->id_str, ":tw_screen_name" => $me ->screen_name, ":tw_access_token" => $reply ->oauth_token, ":iw_access_token_secret" => $reply ->oauth_token_secret ); |
で作成し
1 | $stmt ->execute( $params ); |
で $stmt へデータを格納する
格納したデータをユーザの変数にいれるため
1 | $myId = $dbh ->lastInsertId(); |
で追加したIDを取得する
これでIDが判明するので
sqlでこのユーザの情報を取得
1 2 3 4 | $sql = "select * from users where id = :id limit 1" ; $stmt = $dbh ->prepare( $sql ); $stmt ->execute( array ( ":id" => $myId )); |
$user = $stmt->fetch();
とすることで、ユーザ情報取得している