准备语句失败但未返回错误

时间:2015-08-04 14:14:35

标签: php mysql mysqli

由于一些奇怪的原因,查询的准备失败,我检查了一万次,参数是正确的以及表。这是我的代码:

zipOut.write(fileNameAndPath, actualFile)

}

我尝试在else对象中进行打印,但我只得到了

这个词
  

执行()失败:

foreach($decoded as $caption)
{
if($stmt = $mysqli->prepare("SELECT id, leagueCode FROM league"))
{
    $stmt->bind_result($id, $leagueCode);
    $stmt->execute();
    var_dump($stmt);
    while($stmt->fetch())
    {
        if($leagueCode == $caption['league'])
        {
            if ($stmt = $mysqli->prepare("INSERT INTO soccerseason (id, caption, league, years, numberOfTeams, numberOfGames, lastUpdated, self, teams, fixtures, leagueTable) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")) 
            {
                $id_fk = $id;
                $caption = $caption['caption'];
                $league = $caption['league'];
                $years = $caption['year'];
                $not = $caption['numberOfTeams'];
                $nog = $caption['numberOfGames'];
                $lu = $caption['lastUpdated'];
                $self = $caption['_links']['self']['href'];
                $teams = $caption['_links']['teams']['href'];
                $fix = $caption['_links']['fixtures']['href'];
                $lt = $caption['_links']['leagueTable']['href'];

                if ($stmt->bind_param("isssiisssss", $id_fk, $caption, $league, $years, $not, $nog, $lu, $self, $teams, $fix, $lt)) 
                {
                    if ($stmt->execute()) 
                    {
                        echo "Done!";
                    } 
                    else 
                    {
                        die($mysqli->error);
                    }
                } 
                else 
                {
                    die($mysqli->error);
                }
            } 
            else 
            {

                die('execute() failed: ' . $mysqli->error);
            }
        }
    }
}

似乎else { die('execute() failed: ' . $mysqli->error); } 为空,因为它没有打印,为什么会发生这种情况?我做错了什么?

1 个答案:

答案 0 :(得分:0)

我终于找到了问题,并且我意识到如果由于某种原因使用相同的连接,对象的参数将丢失,因此在执行相同的参数后必须使用$stmt-> store_result();。 我解决了这个问题,希望我的回答能有所帮助。