我试图根据表中结果的数量运行不同的查询。
我有以下内容,但它只输出最后的文本,而不是“回声”数据?
谁能看到我做错了什么?
<?php
require 'dbconfig.php';
class User {
function checkUser($uid, $oauth_provider, $username, $email, $twitter_otoken, $twitter_otoken_secret)
{
$query = "SELECT * FROM `users` WHERE oauth_uid = '$uid' and oauth_provider = '$oauth_provider'";
$result = $DBH->query($query);
if (!empty($result)) {
echo 'user';
} else {
echo 'no user';
}
$DBH = null;
}
}
?>
Test page loads
打电话给班级
在另一页上,我用下面的方式给我的班级打电话
...else {
$twitter_otoken=$_SESSION['oauth_token'];
$twitter_otoken_secret=$_SESSION['oauth_token_secret'];
$email='';
$uid = $user_info->id;
$username = $user_info->name;
$user = new User();
$userdata = $user->checkUser($uid, 'twitter', $username,$email,$twitter_otoken,$twitter_otoken_secret);
if(!empty($userdata)){
session_start();
$_SESSION['id'] = $userdata['id'];
$_SESSION['oauth_id'] = $uid;
$_SESSION['username'] = $userdata['username'];
$_SESSION['oauth_provider'] = $userdata['oauth_provider'];
header("Location: splash.php");
}
}
} else {
// Something's missing, go back to square 1
header('Location: login-twitter.php');
}
?>
配置
$host = 'localhost';
$dbname = 'dbname was here';
$user = 'access';
$pass = 'access';
try {
$DBH = new PDO("mysql:host=$host;dbname=$dbname", $user, $pass);
$DBH->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
} catch(PDOException $e) {
echo $e->getMessage();
}
?>