setAttribute(PDO::ATTR_EMULATE_PREPARES, false); // DB 関連エラーは例外を発生させる $dbh->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION); // タイムゾーンを JST に $dbh->query("SET SESSION time_zone='Asia/Tokyo'"); // トランザクション開始 $dbh->beginTransaction(); // アカウントID を決定。Cookie にあればそれを使う。なければ 1 とする。 if ( isset($_COOKIE['account_id']) && $_COOKIE['account_id'] != '' ){ $account_id = $_COOKIE['account_id']; } else { $account_id = 1; } // XSS 対策。& < > " ' などを実体参照化。 function myesc($str) { return htmlspecialchars($str, ENT_QUOTES, 'UTF-8'); } // フォローまたはフォロー解除処理 if ( isset($_REQUEST['account_id_followee']) && $_REQUEST['account_id_followee'] != '' ){ $follow_mode = $_REQUEST['follow_mode']; $account_id_followee = $_REQUEST['account_id_followee']; if ( $follow_mode == 'follow' ){ // フォロー処理 $sql = "insert ignore into follow (account_id_followee, account_id_follower) values (?, ?)"; $stmt = $dbh->prepare($sql); $stmt->execute(array($account_id_followee, $account_id)); $dbh->commit(); } else if ( $follow_mode == 'unfollow' ){ // フォロー解除処理 $sql = "delete from follow where account_id_followee = ? and account_id_follower = ?"; $stmt = $dbh->prepare($sql); $stmt->execute(array($account_id_followee, $account_id)); $dbh->commit(); } } // 新規メッセージがあれば if ( isset($_REQUEST['new_message']) && $_REQUEST['new_message'] != '' ){ // 先頭30バイトを取得 $new_message = mb_substr($_REQUEST['new_message'], 0, 30); // レコード INSERT。 $sql = "INSERT INTO tweet (account_id, message) VALUES (:account_id, :message)"; $stmt = $dbh->prepare($sql); $stmt->bindParam(':account_id', $account_id, PDO::PARAM_INT); $stmt->bindParam(':message', $new_message, PDO::PARAM_STR); $res = $stmt->execute(); $dbh->commit(); } ?>

あなたの情報

prepare('select count(*) as tweet_count, sleep(1) from tweet where account_id = ?'); $stmt->execute(array($account_id)); $res = $stmt->fetch(); $tweet_count = $res['tweet_count']; $stmt = $dbh->prepare('select count(*) as follow_count, sleep(1) from follow where account_id_follower = ?'); $stmt->execute(array($account_id)); $res = $stmt->fetch(); $follow_count = $res['follow_count']; $stmt = $dbh->prepare('select count(*) as follower_count from follow where account_id_followee = ?'); $stmt->execute(array($account_id)); $res = $stmt->fetch(); $follower_count = $res['follower_count']; $stmt = $dbh->prepare ('select account_id, account_name from account where account_id <> ? limit 100'); $stmt->execute(array($account_id)); $account_list=[]; foreach ( $stmt->fetchAll () as $row ) { $account_list[$row['account_id']] = $row['account_name']; } ?>

account_id

ツイート数

フォロー数

フォロワー数

デバッグ情報

SERVER_ADDR:

おすすめユーザ

フォロー

フォロワー

?" method="post"> ツイートする:

prepare ('select * from tweet where account_id = ? ORDER BY create_timestamp DESC LIMIT 5'); $stmt->execute(array($account_id)); foreach ( $stmt->fetchAll () as $row ) { ?>