$ stmt-> store_result()不返回mysqli_result

时间:2015-06-19 19:38:22

标签: php mysql

也许这是一个重复的问题,但我已经阅读了很多处理这个问题的线程,我找不到解决方案,如果这确实是一个重复的问题,如果你不介意给我一个链接,我道歉可以帮我。 问题是这样的: 由于我的托管计划的原因我不能使用'mysqli_stmt_get_result()'所以我尝试更改我写的脚本(我只是学习php),但是你运行查询无法获得咨询结果如果obtenia使用'mysqli_stmt_get_result()',作为替代,我试图用'mysqli_store_result'得到那个结果,根据文档也可以阅读(据我所知)“返回缓冲结果对象或如果发生错误则返回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

请不要错过任何帮助

0 个答案:

没有答案