1
我需要将Facebook信息保存到MySQL表中。我使用PHP SDK从用户获取数据。当我得到数据时,这些数据都在关联数组中。我需要解析这个数组到MySQL数据库。将Facebook信息保存到Mysql
<?php
require '/src/facebook.php';
$dbname = '';
$dbpass = '';
$dbuser = '';
$dbhost = '';
$appId = '';
$secret = '';
mysql_connect($dbhost, $dbuser, $dbpass);
mysql_select_db($dbname);
$facebook = new Facebook(array(
'appId' => $appId,
'secret' => $secret,
));
$user = $facebook->getUser();
$access_token = 'fb_'.$appId.'_access_token';
if ($user) {
try {
$user_profile = $facebook->api('/me');
} catch (FacebookApiException $e) {
error_log($e);
$user = null;
}
}
if ($user) {
$logoutUrl = $facebook->getLogoutUrl();
} else {
$loginUrl = $facebook->getLoginUrl(
array(
'scope' => 'user_about_me,user_activities,user_birthday'
)
);
}
$sql_insert = "INSERT INTO users (user_id,username,access_token) VALUES ('$user_profile[id]','$user_profile[username]','$_SESSION[$access_token]')";
$sql_select = "SELECT user_id FROM users WHERE user_id='$user_profile[id]'";
$res = mysql_query($sql_select);
if(!mysql_num_rows($res) > 0) { mysql_query($sql_insert); }
?>
这个过程中返回我
Array
(
[id] => 1088214852
[name] => User Name
[first_name] => User
[last_name] => Name
[link] => http://www.facebook.com/user.name
[username] => user.name
[birthday] => 24/12/2011
[hometown] => Array
(
[id] => 107833015912178
[name] => NY
)
[location] => Array
(
[id] => 109589969066408
[name] => CA
)
这仅仅是该阵列的一部分。
感谢您的建议。 顺便说一句:嫁给圣诞节和新年快乐。
所以你想让别人给你编码解析器:)? – ScarletAmaranth 2011-12-24 14:12:45
不,我需要帮助如何解析代码;) – 2011-12-24 14:20:05
这似乎是一个简单的数据库使用问题。 1)识别要捕获的数据(内容的类型 - text/integer/boolean),2)构建数据库,3)构建查询/语句以与数据库交互,4)构建包含这些语句的PHP,5),6, )利润! – 2011-12-24 14:53:38