【问题标题】:Object of class SQLite3Result could not be converted to stringSQLite3Result 类的对象无法转换为字符串
【发布时间】:2018-02-23 04:24:04
【问题描述】:

我正在尝试从 SQLite DB 获取响应,在 PHP 文件上使用 XHR,但我不确定如何处理返回的 SQLite 对象目前,我只是在尝试 console.log响应,但我收到标题中的错误。我是否需要对响应进行字符串化?

<?php
$database = new SQLite3('cookieOrders.sqlite');

$statement = $database->prepare('SELECT creation_time FROM orders WHERE order_id = 1;');
$result = $statement->execute();

echo $result;

?>

-

function populateOrders() {
  var x = new XMLHttpRequest();
  x.onreadystatechange=function(){
  if (x.readyState==4 && x.status==200){
    var response = x.responseText;
    console.log(response);
    }
  }
  x.open("GET","./php/queryDB.php",true);
  x.send();
  return false;
}

【问题讨论】:

    标签: javascript php sqlite xmlhttprequest


    【解决方案1】:

    您必须获取数据。目前您正在尝试 echo 一个 SQLite3Result 对象,这是 execute() 的结果:

    $result = $statement->execute() ;
    $row = $result->fetchArray() ;
    echo json_encode($row) ;
    // or echo $row['creation_time'] ;
    // or print_r($row) ;
    

    【讨论】:

      猜你喜欢
      • 2019-01-31
      • 1970-01-01
      • 2022-01-05
      • 2015-07-27
      • 2012-04-29
      • 2011-04-06
      • 2011-11-30
      • 2011-08-30
      相关资源
      最近更新 更多