Php MySQLi准备的查询在第一次查询后失败
我有一个函数,可以从一个表中选择大量信息。然后启动另一个函数,从另一个表中获取一些信息 以下是缩短的代码:Php MySQLi准备的查询在第一次查询后失败,php,mysql,mysqli,prepared-statement,Php,Mysql,Mysqli,Prepared Statement,我有一个函数,可以从一个表中选择大量信息。然后启动另一个函数,从另一个表中获取一些信息 以下是缩短的代码: $con = new mysqli("localhost", "user", "password"); if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit(); } $con->select_db("stories_test"); g
$con = new mysqli("localhost", "user", "password");
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
$con->select_db("stories_test");
getStories($con);
function getStories($con) {
... //get's a load of data from one table
$result = getStoryName($con, $stringstoryid);
... //More stuff here
}
function getStoryName($con) {
$newquery = "SELECT storyname, genre FROM stories WHERE storyid = 'Anewstory9856'";
if ($stmt = $con->prepare($newquery)) {
echo $newquery;
$stmt->execute();
$stmt->bind_result($storname, $genre);
while ($stmt->fetch()) {
$resultarray = array (
'storname' => $storname,
'genre' => $genre
);
}
}
else {
echo 'statement failed';
}
return $resultarray;
}
我从第二个查询中得到的只是“语句失败”。
我已经在一个单独的脚本中尝试了完全相同的查询,它运行得很好,但在这里它似乎在“prepare”失败
有人有任何线索吗?查找用于获取最后一个错误的API函数。可能有更多的信息隐藏在里面,这会让事情变得显而易见。
echo$con->error
告诉你什么?它保存真正的错误消息。$stmt->close()代码>。您的语句中可能还剩下一些内容。是的,在getStories()
函数中,您会说“从一个表中获取数据负载”,如果您没有从中获取所有行,您可能必须关闭一个打开的语句。这听起来很合理,我会测试,尽管我的笔记本电脑刚刚耗尽了电池。马上回来