在循环中重新声明函数


Redeclare function in loop

我不知道该怎么做。我正在使用twitteroauth.php库,并从数据库查询中获取用户令牌和令牌机密。这是代码:

while($row = mysql_fetch_array($m))
{   
    $connection = new TwitterOAuth($consumerKey, $consumerSecret, $oauthToken, $oauthTokenSecret);
    $consumerKey = "#####";
    $consumerSecret = "#####";
    $oauthToken = $row['oauth_token'];
    $oauthTokenSecret = $row['oauth_token_secret'];
    $userName = $row['username'];
    $query = mysql_query("select url from retweets order by rand() limit 1");
    $row = mysql_fetch_assoc($query);
    $retweet = basename($row['url']);
    $method = 'statuses/retweet/'.$retweet.'';
    twitterOAuth($method, $connection->post($method), $connection->http_code, $userName);
}

如果mysql有多个结果,它会循环并显示:

 Fatal error: Cannot redeclare random_from() (previously declared in /usr/share/nginx/www/twitteroauth/twitteroauth.php:199) in /usr/share/nginx/www/twitteroauth/twitteroauth.php on line 199

由于$connection变量依赖于mysql查询中的$oauthToken$oauthTokenSecret,我无法将其移出循环,那么我该如何制作它,以便在每个循环中使用它而无需重新声明呢?

提前谢谢!

更新:这是推特OAuth

function twitterOAuth($method, $response, $http_code, $userName, $parameters = '') {
        if($http_code == 200){
            echo "retweeted successfully @".$userName."<br />";
        }else{
            echo "an error has occurred while retweeting @".$userName."";
            echo "<br />";
            print_r($response);
        }
}

它需要看起来像这样。。。

while($row = mysql_fetch_array($m))
{   
$consumerKey = "#####";
$consumerSecret = "#####";
$oauthToken = $row['oauth_token'];
$oauthTokenSecret = $row['oauth_token_secret'];
$userName = $row['username'];
$connection = new TwitterOAuth($consumerKey, $consumerSecret, $oauthToken, $oauthTokenSecret);
$query = mysql_query("select url from retweets order by rand() limit 1");
$row = mysql_fetch_assoc($query);
$retweet = basename($row['url']);
$method = 'statuses/retweet/'.$retweet.'';
twitterOAuth($method, $connection->post($method), $connection->http_code, $userName);
}

在声明要传递给它的变量之前,您已经声明了它…