简体   繁体   中英

PHP MySQL Array Confusion

I am developing a Twitter application. My keys are stored in the database for the users, so it sends each user their key. Basicly, user 1 keys is X, and users 2 key is Y, (example, not for me), and you need their keys to send the tweet.

So I am trying to use all the user's keys in the database as an array. But it is showing up as this Xy, they are being combined and it thinks it is one whole key.

How can I get PHP to know that those are two different keys?

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);
}

它似乎是串联的,因为回声不包含空格,请尝试

echo "$oAuthToken\n";

Try:

<?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
}
?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM