【发布时间】:2016-07-01 01:39:16
【问题描述】:
我的代码中有一个查询,看起来像这样
$edi_transaction_id = mysqli_query($conn, "SELECT a.edi_transaction_id FROM edi_transaction_detail a JOIN reference_number b JOIN edi_transaction c WHERE a.asn_number = '$asn_number' AND a.edi_transaction_id = c.edi_transaction_id LIMIT 1");
我想获取该查询的值并将其存储在 $edi_transaction_id 变量中。我已经认为这会运行,因为直接在 mysql 数据库上完成时它可以正常工作,但是当我将它集成到我的代码中时,这是错误
<b>Catchable fatal error</b>: Object of class mysqli_result could not be converted to string in <b>/home/ationgzon/WebService/edi_864_824_files.php</b> on line <b>53</b><br />
这是 edi_864_824_files.php 中的第 53 行
mysqli_query($conn, "INSERT INTO `edi_864_824`(`edi_transaction_id`, `trading_partner`, `trans_date`, `issue`, `reference_number_id`) VALUES ($edi_transaction_id, '$trading_partner', '$trans_date', '$message', $reference_number_id)");
我该怎么做才能将它插入到我的数据库中。
【问题讨论】:
-
mysqli_query()返回一个 mysqli_result 对象,而不是字符串 -
为什么read the manual这么难?都是用例子写的!
-
如果您只需要
edi_transaction_id进行插入,请查看this question/answer 它显示了如何使用SELECT的结果来INSERT INTO