同一连接中的连续查询无效

时间:2013-04-29 17:16:21

标签: php

以下代码工作得很好,但是行$connection->query('call user_create(145552, \'a@a.com\');');没有在数据库中创建用户。

function updateFacebook($id) {

    $connection = mysqli_connect('localhost', 'root', '', 'databasename');
    $count = $connection->query('call user_by_facebook_read(' . $id . ');')->num_rows;

    if ($count == 0) {

        $request = \Slim\Slim::getInstance()->request();
        $body = $request->getBody();
        $json = json_decode($body);
        $token = $json->token;

        $facebook = new Facebook(array(
            'appId' => 'value',
            'secret' => 'value',
            'cookie' => true
        ));

        $facebook->setAccessToken($token);

        $facebook->api('/me/feed', 'post', array(
            'message' => 'message',
            'picture' => 'https://www.google.com.br/images/srpr/logo4w.png',
            'link' => 'https://www.google.com.br',
            'description' => 'description',
            'name' => 'name',
            'caption'=> 'caption'
        ));

        $connection->query('call user_create(145552, \'a@a.com\');');

    }

    $connection->close;

    $json = json_encode(array(
        'r' => true
    ));

    echo $json;     

}

如果我运行以下代码,它也可以正常工作:

$connection = mysqli_connect('localhost', 'root', '', 'databasename');
$connection->query('call user_create(145552, \'a@a.com\');');
$connection->close;

如果我在$count之后关闭连接并在user_create调用之前再次打开它,它也可以正常工作。

发生了什么事?

1 个答案:

答案 0 :(得分:1)

您需要对结果运行->close(),但您放弃了。{p>所以:

 $result = $connection->query(..);
 $count = $result->num_rows;
 $result->close();

and after CALL()s in MySQLi it seems to need this:

 $connection->next_result();