2012-10-09 126 views
0

我正在開發一個Twitter應用程序。我的密鑰存儲在用戶的數據庫中,因此它會向每個用戶發送密鑰。基本上,用戶1的密鑰是X,用戶2的密鑰是Y(例如,不適用於我),並且您需要他們的密鑰才能發送推文。PHP MySQL陣列混亂

所以我試圖在數據庫中使用所有用戶的密鑰作爲數組。但它顯示爲這個Xy,他們正在合併,並認爲它是一個完整的關鍵。

我該如何讓PHP知道這些是兩個不同的鍵?

require('config.php'); 
$query = "SELECT * FROM users"; 
$result = mysql_query($query) or die(mysql_error()); 
while($row = mysql_fetch_array($result)){ 
$oauthtoken2 = $row['oauth_token']; 
$oauthsecret2 = $row['oauth_token_secret']; 
$oAuthToken = $oauthtoken2; 
$oAuthSecret = $oauthsecret2; 
echo "$oAuthToken"; 
require_once('twitteroauth.php'); 
$tweet = new TwitterOAuth($consumerKey, $consumerSecret, $oAuthToken, $oAuthSecret); 
} 
+0

「所以我想使用在所有用戶的密鑰數據庫作爲數組「 - 一個用戶 - >一個密鑰。將它存儲爲一個字符串 – zerkms

+1

如果你只是學習PHP,你應該開始學習PDO,從長遠來看它會更好 –

回答

0

它似乎要連接,因爲回聲不包括空間,嘗試

echo "$oAuthToken\n"; 
0

嘗試:

<?php 
require('config.php'); 
require_once('twitteroauth.php'); 

$query = "SELECT * FROM users"; 
$result = mysql_query($query) or die(mysql_error()); 

while($row = mysql_fetch_array($result)){ 
    $oauthtoken2 = $row['oauth_token']; 
    $oauthsecret2 = $row['oauth_token_secret']; 
    $oAuthToken = $oauthtoken2; 
    $oAuthSecret = $oauthsecret2; 
    //echo "$oAuthToken"; 
    $tweet = new TwitterOAuth($consumerKey, $consumerSecret, $oAuthToken, $oAuthSecret); 

    // do what ever you need to do here with the $tweet object. 

    //unset($tweet); - unset it here, then loop to the next token/secret pair 
} 
?>