Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/263.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 $stmt->;store_result()不返回mysqli_结果_Php_Mysql - Fatal编程技术网

Php $stmt->;store_result()不返回mysqli_结果

Php $stmt->;store_result()不返回mysqli_结果,php,mysql,Php,Mysql,也许这是一个重复的问题,但我已经阅读了很多关于这个问题的帖子,我找不到解决方案,如果这确实是一个重复的问题,我道歉,如果你不介意给我一个链接,可以帮助我。 问题是: 由于我的托管计划的原因,我不能使用“mysqli_stmt_get_result()”,因此我尝试更改我编写的脚本(我只是在学习php),但是您运行查询无法获得咨询结果,如果obtenia使用“mysqli_stmt_get_result()”,作为一种替代方法,我尝试使用“mysqli_store_result”获得该结果,根据a

也许这是一个重复的问题,但我已经阅读了很多关于这个问题的帖子,我找不到解决方案,如果这确实是一个重复的问题,我道歉,如果你不介意给我一个链接,可以帮助我。 问题是: 由于我的托管计划的原因,我不能使用“mysqli_stmt_get_result()”,因此我尝试更改我编写的脚本(我只是在学习php),但是您运行查询无法获得咨询结果,如果obtenia使用“mysqli_stmt_get_result()”,作为一种替代方法,我尝试使用“mysqli_store_result”获得该结果,根据alcanso-to-read文档(据我所知)“如果发生错误,将返回缓冲结果对象或FALSE。”是否(如果一切顺利)给我与“mysqli_stmt_get_result()”相同的结果,并且只应返回“FALSE”万一出了问题,但我所做的总是得到布尔值=真。 有人能帮我一下吗?我做错了吗?“mysqli_stmt_get_result()”的简单替代品? 这是我必须编写的代码片段:

$link = new mysqli(
    "localhost",
    "root",
    "RootPass",
    "DB"
);
echo "\n\n\n";
if (mysqli_connect_errno()){
echo "Failed to connect to MySQL: " . mysqli_connect_error();
exit();
}
if($_GET){
  $where_value = trim(htmlspecialchars($_GET["where"]));
}else{
  if(count($argv)>1){
    $where_value = trim($argv[1]);
  }else{
    $where_value = '';
  }
}
if($where_value != ''){
  if($stmt = $link->prepare('SELECT * FROM Tabla_1 WHERE ID=?')){
    $stmt->bind_param('i', $where_value);
   }else{
    echo mysqli_stmt_errno;
    exit();
  }
}else{
  if(!$stmt = $link->prepare('SELECT * FROM Table_1')){
    echo mysqli_stmt_errno;
    exit();
  }
}
$stmt->execute();
$result = $stmt->store_result(); // Store "true" but must be 'mysqli_result'

// From this point none work because $result is a boolean not a 'mysqli_result'
$resultArray = array();
$tempArray = array();
while($row = $result->fetch_array(MYSQLI_NUM)){
  $tempArray = $row;
  array_push($resultArray, $tempArray);
}
mysqli_close($con);
echo json_encode($resultArray);
“Mysqli_stmt_bind_result”不是我的选项,因为该表有很多列,除非您可以为“Mysqli_stmt_bind_result”使用数组

我的系统是:

php --version
PHP 5.6.9-0+deb8u1 (cli) (built: Jun  5 2015 11:03:27) 
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2015 Zend Technologies
    with Zend OPcache v7.0.4-dev, Copyright (c) 1999-2015, by Zend Technologies
lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description:    Debian GNU/Linux 8.1 (jessie)
Release:        8.1
Codename:       jessie
uname -a
Linux Iwakura-PC 3.16.0-4-amd64 #1 SMP Debian 3.16.7-ckt11-1 (2015-05-24) x86_64 GNU/Linux

如果您有任何帮助,我们将不胜感激

在您的输入中调用
htmlspecialchars
,这通常是一件坏事。该函数仅用于在显示内容时调用。为什么不检查
$stmt->execute()
的结果呢?上面说
store\u result()
返回
bool
,而不是
mysqli\u result
。你为什么期待不同的东西?
echo mysqli\u stmt\u errno应该是
echo$stmt->errno
(请参阅)。但是为什么要回显错误号而不是错误消息呢?之所以会出现
echo mysqli_stmt_errno
,是因为该脚本已从“过程式风格”转换为“面向对象风格”,忘记了更改它,关于您给我的文档链接,我想我看到了哪里出了问题,我正在读这篇文章,你能告诉我该怎么办吗?如何获得与mysqli\u stmt\u get\u result()
相同的结果?