尝试连接关闭时出现mysqli_错误

时间:2014-09-16 03:41:51

标签: php mysqli

我正在尝试在调用过程后清空mysqli查询。这是我的代码:

$mysqli=new mysqli($mysql_host,$mysql_user,$mysql_password,$mysql_db);
if ($mysqli->connect_error) 
{
    die('Connect Error (' . $mysqli->connect_errno . ') ' . $mysqli->connect_error);
}
$mysqli->query("SET NAMES UTF8");
echo"blockSeparate";
$_POST['address']='Str';
if($clientIntercome=$mysqli->prepare("CALL mbusGetClientIntercomeByAddress(?)"))
{
    $clientIntercome->bind_param("s",$_POST['address']);
    $clientIntercome->execute();
    $clientIntercome->bind_result($id,$flat,$phone,$redirectPhone);
    while($clientIntercome->fetch())
    {
        echo"".$id." ".$flat." ".$phone." ".$redirectPhone."\n";
    }
}
else
{
    echo"SMTH is wrong";
}
$clientIntercome->close();
while(true)
{
    echo"WORKS";
    $mysqli->store_result();
    if (!$mysqli->more_results())
    {
        break;
    }
    if (!$mysqli->next_result())
    {
        break;
    }           
}
echo"blockSeparate";
if($clientKeys=$mysqli->prepare("CALL mbusGetClientKeys(?)"))
{
    echo"Here works too";
    $clientKeys->bind_param('i',1);
    $clientKeys->execute();
    $clientKeys->bind_result($rf_id,$phone);
    while($clientKeys->fetch())
    {
        echo"".$rf_id." ".$phone."\n";
    }
    //$clientKeys->close();
}
else
{
    echo$mysqli->error;
}
$mysqli->close();

我初始化$_POST['address']在服务器上测试这个脚本,通常是通过ajax使用它。

var address=$("#cfgAddress").val();
var data={address:address};
$.ajax(
{
    type: "POST",
    url: "./getUserFlatPhone.php",
    data: data,
    success: function(data, textStatus, jqXHR)
    {
        console.log(data);
//some work
    }
});

如果我使用未注释的strng尝试它会返回PHP内部服务器错误,但是如果它被注释没有错误,但是下一个查询返回commans不同步错误。但是这个代码(while循环清空mysqli过程调用)在我的应用程序中正常工作。此外,如果我在浏览器中运行它而不是通过jquery它返回没有错误,但不发布结果。 编辑:更改了我的工作失败的注释字符串

2 个答案:

答案 0 :(得分:0)

  1. 使用例外来获取确切的错误/问题。
  2. 使用Close()仅结束mysqli连接。
  3. 试试这个:http://pastebin.com/SsYHsALL

答案 1 :(得分:0)

此行不是mysqli连接。所以请不要{我} close()。改为删除它。

$clientIntercome->close();

the correct way to close the connection per the manual中的这一行:

$mysqli->close();
相关问题