Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/56.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在数组中使用TwitterOAuth_Php_Mysql_Twitter - Fatal编程技术网

Php 在数组中使用TwitterOAuth

Php 在数组中使用TwitterOAuth,php,mysql,twitter,Php,Mysql,Twitter,我使用的是Abraham的TwitterOAuth,有一个函数我想在使用PHP的页面中重复多次。我建立了一个数据库,其中包含用户的身份验证密钥和机密列表,其中包含以下信息: Table Name: twitter Fields: id, key, secret (primary - id, with auto_increment) 我需要这样做,以便为每个键创建一个新连接。要做到这一点,我必须使用这个函数 $connection = new TwitterOAuth(APP KEY, APP

我使用的是Abraham的TwitterOAuth,有一个函数我想在使用PHP的页面中重复多次。我建立了一个数据库,其中包含用户的身份验证密钥和机密列表,其中包含以下信息:

Table Name: twitter
Fields: id, key, secret (primary - id, with auto_increment)
我需要这样做,以便为每个键创建一个新连接。要做到这一点,我必须使用这个函数

$connection = new TwitterOAuth(APP KEY, APP SECRET, USER KEY, USER SECRET);
最初,我每次都在一个数组中键入,比如$connection['0']、$connection['1']等等

在使用mySQL时,我收到一个错误,告诉我不能在数组中生成函数,所以编码天才们,你认为我应该怎么做

顺便说一下,这是我的代码:

$con=mysqli_connect("host","username","password","twtid");
// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }

$result = mysqli_query($con,"SELECT * FROM twitter");
while($row = mysqli_fetch_array($result)) {
        $id = $row['id'];
        $connection = new TwitterOAuth(KEY, SECRET, $row['key'], $row['secret']);
}

错误:致命错误:无法在

中将TwitterOAuth类型的对象用作数组。您没有将对象放入数组中,只是每次通过循环时使用不同的TwitterOAuth对象覆盖相同的变量。试试这个:

$connection = array()
while ($row = mysqli_fetch_array($result)) {
    $connection[$row['id']] = new TwitterOAuth(KEY, SECRET, $row['key'], $row['secret']);
}