“如何调试”;类mysqli的对象无法转换为字符串;PHP中的错误?

“如何调试”;类mysqli的对象无法转换为字符串;PHP中的错误?,php,sql-server,mysqli,Php,Sql Server,Mysqli,我正在做我的学术项目,我被困在我的搜索功能中,我尝试运行的查询在MySQL服务器上运行顺利,但当我尝试在应用程序上运行它时,它给了我如下错误: 可捕获致命错误:类mysqli的对象无法转换为……….中的字符串 代码片段如下所示: object(mysqli)#1 (19) { ["affected_rows"]=> int(0) ["client_info"]=> string(79) "mysqlnd 5.0.11-dev - 20120503 - $Id: f373ea5dd55

我正在做我的学术项目,我被困在我的搜索功能中,我尝试运行的查询在MySQL服务器上运行顺利,但当我尝试在应用程序上运行它时,它给了我如下错误:

可捕获致命错误:类mysqli的对象无法转换为……….中的字符串

代码片段如下所示:

object(mysqli)#1 (19) { ["affected_rows"]=> int(0) ["client_info"]=> string(79) "mysqlnd 5.0.11-dev - 20120503 - $Id: f373ea5dd5538761406a8022a4b8a374418b240e $" ["client_version"]=> int(50011) ["connect_errno"]=> int(0) ["connect_error"]=> NULL ["errno"]=> int(0) ["error"]=> string(0) "" ["error_list"]=> array(0) { } ["field_count"]=> int(0) ["host_info"]=> string(20) "localhost via TCP/IP" ["info"]=> NULL ["insert_id"]=> int(0) ["server_info"]=> string(6) "5.6.21" ["server_version"]=> int(50621) ["stat"]=> string(130) "Uptime: 550 Threads: 1 Questions: 5 Slow queries: 0 Opens: 70 Flush tables: 1 Open tables: 63 Queries per second avg: 0.009" ["sqlstate"]=> string(5) "00000" ["protocol_version"]=> int(10) ["thread_id"]=> int(4) ["warning_count"]=> int(0) } 
string(413) "SELECT `vendor`.`v_id`,`vendor`.`v_name`,`vendor`.`v_img`,`contacts`.`cont_addr`,`contacts`.`cont_phn`,`fooditem`.`item_name`,`fooditem`.`fi_price`,`fooditem`.`fc_desc` FROM vendor LEFT JOIN stfood.`contacts` ON `vendor`.`cont_id` = `contacts`.`cont_id` LEFT JOIN stfood.`fooditem` ON `vendor`.`v_id` = `fooditem`.`v_id` WHERE stfood.`vendor`.`v_name` LIKE '%vend%' OR stfood`fooditem`.`item_name` LIKE '%vend%';" 
数据库连接:

<?php
error_reporting(E_ALL);
define("DBNAME","foodfood");
global $con;
$servername = "localhost";
$username = "root";
$password = "passport";

// Create connection
$con = mysqli_connect($servername, $username, $password);

// Check connection
if (!$con) {
    die("Connection failed: " . mysqli_connect_error());
}
?>
现在,当我运行这段代码时,通过输入搜索变量$keysearch(这些变量被过滤以防任何可能的注入攻击)。我在该行中得到一个错误,即:

LEFT JOIN ".DBNAME.".`fooditem` ON `vendor`.`v_id` = `fooditem`.`v_id`  WHERE `vendor`.`v_name` LIKE '%".$keysearch."%' OR `fooditem`.`item_name` LIKE '%".$keysearch."%';";
更新:我调试了代码并提供了更多信息。 我对搜索页面中的变量进行了var_转储,从中提取$keyword。一切似乎都很好,我在var_转储中得到了输入的搜索字符串。现在,当在我输入SQL语句的下一个文件中解析这个关键字时,这就变得有趣了。 我有这个关键字的var_dump的输出,现在可以看到mysqli对象,如下所示:

object(mysqli)#1 (19) { ["affected_rows"]=> int(0) ["client_info"]=> string(79) "mysqlnd 5.0.11-dev - 20120503 - $Id: f373ea5dd5538761406a8022a4b8a374418b240e $" ["client_version"]=> int(50011) ["connect_errno"]=> int(0) ["connect_error"]=> NULL ["errno"]=> int(0) ["error"]=> string(0) "" ["error_list"]=> array(0) { } ["field_count"]=> int(0) ["host_info"]=> string(20) "localhost via TCP/IP" ["info"]=> NULL ["insert_id"]=> int(0) ["server_info"]=> string(6) "5.6.21" ["server_version"]=> int(50621) ["stat"]=> string(130) "Uptime: 550 Threads: 1 Questions: 5 Slow queries: 0 Opens: 70 Flush tables: 1 Open tables: 63 Queries per second avg: 0.009" ["sqlstate"]=> string(5) "00000" ["protocol_version"]=> int(10) ["thread_id"]=> int(4) ["warning_count"]=> int(0) } 
string(413) "SELECT `vendor`.`v_id`,`vendor`.`v_name`,`vendor`.`v_img`,`contacts`.`cont_addr`,`contacts`.`cont_phn`,`fooditem`.`item_name`,`fooditem`.`fi_price`,`fooditem`.`fc_desc` FROM vendor LEFT JOIN stfood.`contacts` ON `vendor`.`cont_id` = `contacts`.`cont_id` LEFT JOIN stfood.`fooditem` ON `vendor`.`v_id` = `fooditem`.`v_id` WHERE stfood.`vendor`.`v_name` LIKE '%vend%' OR stfood`fooditem`.`item_name` LIKE '%vend%';" 
现在,当我将sql查询放入搜索页面本身时,我没有得到指定的错误。但我现在可以按如下方式执行sql查询:

object(mysqli)#1 (19) { ["affected_rows"]=> int(0) ["client_info"]=> string(79) "mysqlnd 5.0.11-dev - 20120503 - $Id: f373ea5dd5538761406a8022a4b8a374418b240e $" ["client_version"]=> int(50011) ["connect_errno"]=> int(0) ["connect_error"]=> NULL ["errno"]=> int(0) ["error"]=> string(0) "" ["error_list"]=> array(0) { } ["field_count"]=> int(0) ["host_info"]=> string(20) "localhost via TCP/IP" ["info"]=> NULL ["insert_id"]=> int(0) ["server_info"]=> string(6) "5.6.21" ["server_version"]=> int(50621) ["stat"]=> string(130) "Uptime: 550 Threads: 1 Questions: 5 Slow queries: 0 Opens: 70 Flush tables: 1 Open tables: 63 Queries per second avg: 0.009" ["sqlstate"]=> string(5) "00000" ["protocol_version"]=> int(10) ["thread_id"]=> int(4) ["warning_count"]=> int(0) } 
string(413) "SELECT `vendor`.`v_id`,`vendor`.`v_name`,`vendor`.`v_img`,`contacts`.`cont_addr`,`contacts`.`cont_phn`,`fooditem`.`item_name`,`fooditem`.`fi_price`,`fooditem`.`fc_desc` FROM vendor LEFT JOIN stfood.`contacts` ON `vendor`.`cont_id` = `contacts`.`cont_id` LEFT JOIN stfood.`fooditem` ON `vendor`.`v_id` = `fooditem`.`v_id` WHERE stfood.`vendor`.`v_name` LIKE '%vend%' OR stfood`fooditem`.`item_name` LIKE '%vend%';" 
现在,如果我将这个查询作为一个查询粘贴到mysql服务器中,查询将失败,如果我删除双引号(“”),然后运行查询,它将成功运行。 现在,我在其他函数中也有类似的语句,它们运行正常,但不是这个。 有人能告诉我哪里出了错吗?? 提前谢谢。

最后,我做到了。。。 带有大量外键的sql查询导致了问题,我在脚本中做了一些更改。 *将搜索词和SQL查询放在同一页上。 *SQL查询中的小更改。
*使用mysqli_result对象上的mysqli_num_行,将结果存储在变量中,并回显到表中。呸……。

当你将
mysqli\uu
mysql\u
混合使用时,通常会出现此错误-你能搜索
mysql\u
并将其转换为
mysqli\u
搜索的mysql吗?我的整个文档中没有结果。之前的答案实际上是错误的,对不起!有人能告诉我我犯了什么错误吗?在这一点上我完全不知道。