2016-10-25 22:16
浏览 35

php - 注意:数组转换为字符串

I am trying to compose a SQL query via php. But I get the notice mentioned in a pretty unusual way.

$tableFieldsQueryFormat=array("hospitals"=>"(location LIKE '%@val%' OR phone_no LIKE '%@val%')","doctors"=>"doc_name LIKE '%@val%'","news"=>"title LIKE '%@val%'","diseases"=>"name LIKE '%@val%'","tips"=>"tip LIKE '%@val%'");
$SQL="SELECT * FROM $tableName WHERE $query_str AND isdeleted='0';"; // Notice is thrown here !!!

I have not treated the '$SQL' variable as an array in any part of the program, in fact I only declared and used it in the above snippet. What could be the reason behind this weird notice? I don't think I've made any syntax or logic errors.

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • drllqg2903 2016-10-25 22:22

    You are seeing this exception because $tableName is an array. When your string is being interpolated $tableName can not be converted to a string.

    Try this instead:

    $SQL = "SELECT * FROM " . explode(",",$tableName) . " WHERE $query_str AND isdeleted='0';";
    解决 无用
    打赏 举报

相关推荐 更多相似问题