php 可捕获的致命错误:无法将类 mysqli_result 的对象转换为字符串

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13020298/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 04:39:49  来源:igfitidea点击:

Catchable fatal error: Object of class mysqli_result could not be converted to string

phpmysqlfatal-error

提问by shane

Trying to get my first multi-table MySQL database but i've gut an error I just can wrap my head around. Can someone please suggest an approach before I toss my computer out a window?

试图获得我的第一个多表 MySQL 数据库,但我遇到了一个错误,我只能回过头来。在我把电脑扔出窗外之前,有人可以建议一种方法吗?

Setup

设置

I have two tables:

我有两个表:

  1. clientswhich has rows: *id, tourbk_id, tourstart, roomtype1, client_name*
  2. tourpriceswhich has rows: *id, tour_id, tourstart, roomtype, roomprice*
  1. 具有行的客户:*id、tourbk_id、tourstart、roomtype1、client_name*
  2. Tourprices包含以下行:*id、tour_id、tourstart、roomtype、roomprice*

Goal

目标

I'm intending for the following query to look, in the clientstable for the tour the client wishes to purchase, compare the tour date + tour name + room type in the clienttable, and echo the price.

我打算在下面的查询来看看,在客户表的客户希望购买的旅游,比较在游览日游+姓名+房型客户表,和回声的价格。

My fubarQuery

我的fubar查询

    $tourquery = "SELECT t.roomprice 
         FROM clients c, tourprices t 
         WHERE c.roomtype1 = t.roomtype 
         AND c.tourstart = t.tourstart
         AND c.tourbk_id = t.tour_id"; 
$tourresult = $db->query($tourquery); 

echo '<strong>',"Per room amount:  ",'</strong>'.$tourresult. "";

$tourresult->free();

As-is, the result is just an error stating: Catchable fatal error: Object of class mysqli_result could not be converted to string

原样,结果只是一个错误说明: 可捕获的致命错误:mysqli_result 类的对象无法转换为字符串

any help is much appreciated.

任何帮助深表感谢。

回答by Landon

The query()function returns a resource, you'll want fetch a record from what's returned from that function. Look at the examples on this pageto learn how to print data from mysql

query()函数返回一个资源,您需要从该函数返回的内容中获取记录。查看此页面上的示例以了解如何从 mysql 打印数据