google web サービスで取得した情報をDB格納
#13 ユーザー情報を格納しよう (1)
http://dotinstall.com/lessons/google_connect_php_v2/9913
を参考に
取得したユーザ情報をDBへ格納
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | $sql "insert into users( google_user_id, google_email, google_name, google_picture, google_access_token, created, modified) values( :google_user_id, :google_email, :google_name, :google_picture, :google_access_token, now(), now())"; |
とする
:google_user_id というように
: がついているのは
prepare() を使うから
この変数に格納された SQL を実行するので
1 | $stmt = $dbh ->prepare( $sql ); |
パラメータを指定するので
1 2 3 4 5 6 | $params = array ( ":google_user_id" => $me ->id. ":google_email" => $me ->email, ":google_name" = $me ->name, ":google_picture" => $me ->picture, ":google_access_token" => $me ->access_token); |
これでパラメータがセットできたので実行
1 | $stmt ->execute( $params ); |