我要直截了當地說到。我在本地主機上使用MAMP構建了一個原型PHP應用程序。PDO數據沒有存儲在db
我想讓註冊轉換對最終用戶儘可能輕鬆。
因此,對於初學者,我使用fb phpsdk獲取所有用戶的圖形數據以無縫地構建用戶配置文件。我已經全部顯示正常。
但是,我拉着頭髮試圖讓數據成功地使用PDO存儲。在我之前使用$ _POST方法和表單輸入成功使用它之後,我成功地獲得了代碼。
我只是不明白爲什麼它不工作沒有$ _POST方法。數據庫設置正常,就像我說過的那樣,我測試了它並使用了下面的PDO代碼。
存儲到DB嘗試使用PDO
require_once 'fbphpsdk/src/facebook.php'; // include the facebook php sdk
$facebook = new Facebook(array(
'appId' => 'xxxx', // app id
'secret' => 'xxxx')// app secret
);
$user = $facebook->getUser();
if ($user) { // check if current user is authenticated
try {
// Proceed knowing you have a logged in user who's authenticated.
$user_profile = $facebook->api('/me');
} catch (Exception $e) {}
}
$user = "xxxx";
$pwd = "xxxx";
$odb = new PDO("mysql:host=localhost;dbname=xxxx;", $user, $pwd);
$q = "INSERT INTO users(u_fullname, age, u_location, u_gender, u_bday, u_employer, u_job) VALUES(:u_fullname, :age, :u_location, :u_firstname, :u_gender, :u_bday, :u_employer, :u_job)";
$query = $odb->prepare($q);
$results = $query->execute(array(
":u_fullname" => $u_fullname,
":age" => $age,
":u_location" => $u_location,
":u_gender" => $u_gender,
":u_bday" => $u_bday,
":u_employer" => $u_employer,
":u_job" => $u_job));
在FB用戶數據(PHP)
$fbuid = $user_profile['id'];
$u_employer = $user_profile['work'][0]['employer']['name'];
$u_job = $user_profile['work'][0]['position']['name'];
$u_firstname = $user_profile['first_name'];
$u_fullname = $user_profile['name'];
$u_location = $user_profile['location']['name'];
$u_gender = ucfirst($user_profile['gender']);
$u_bday = $user_profile['birthday'];
//explode the date to get month, day and year
$u_bday = explode("/", $u_bday);
//get age from date or birthdate
$age = (date("md", date("U", mktime(0, 0, 0, $u_bday[0], $u_bday[1], $u_bday[2]))) > date("md") ? ((date("Y")-$u_bday[2])-1):(date("Y")-$u_bday[2]));?>
任何想法?
哪裏user_profile'獲取填充'$? –
我有一個外部的php文件(通過php require加載)看到我上面的編輯看代碼 –
假設你在本地執行此操作,如果你使用'print_r($ user)',你會得到什麼? –