我使用Facebook Javascript SDK登录并获取用户信息。当我将这些数据保存到mysql数据库时,它只保存1-2条记录。虽然我每次都会收到用户记录。
if($user){
print_r($userInfo);
$userid = $userInfo[id];
$username = $userInfo[name];
$birthday = $userInfo[birthday];
$birthday = date("Y-m-d", strtotime($birthday));
$userlocation = $userInfo[location][name];
$gender = $userInfo[gender];
$useremail = $userInfo[email];
$sql = "INSERT INTO users (userid, username, useremail, birthday, location, gender) VALUES ('$userid', '$username', '$useremail', '$birthday', '$userlocation', '$gender')";
if($result = mysql_query($sql)) {
echo "success";
}
}
用户的表格def是:
1 userid int(20) No None Change Drop Browse distinct values Primary Unique Index Spatial Fulltext
2 username varchar(30) latin1_swedish_ci No None Change Drop Browse distinct values Primary Unique Index Spatial Fulltext
3 useremail varchar(50) latin1_swedish_ci No None Change Drop Browse distinct values Primary Unique Index Spatial Fulltext
4 birthday date No None Change Drop Browse distinct values Primary Unique Index Spatial Fulltext
5 location varchar(30) latin1_swedish_ci No None Change Drop Browse distinct values Primary Unique Index Spatial Fulltext
6 gender varchar(10) latin1_swedish_ci No None Change Drop Browse distinct values Primary Unique Index Spatial Fulltext
使用PDO时:
if($user){
$host = "internal-db.s130813.gridserver.com";
$db = "db130813_fbmooz";
$user = "db130813_adminu";
$pass = "ansari786";
$conn = new PDO("mysql:host=$host;dbname=$db",$user,$pass);
$uid = $userInfo[id];
$uname = $userInfo[name];
$sql = "INSERT INTO users (userid,username) VALUES (:uid,:uname)";
$q = $conn->prepare($sql);
$q->execute(array(':uid'=>$uid, ':uname'=>$uname));
仍然无法保存
答案 0 :(得分:0)
想到了一些想法: