0

嗨,我已经搜索了解决方案并找到了几个答案,并且在对代码进行了多次编辑后没有成功,我直接在这里询问。

$return_arr = array();
$fetch = tep_db_query("select * from products, " . TABLE_PRODUCTS_DESCRIPTION . " WHERE products.products_status = '1' and products.products_id = " . TABLE_PRODUCTS_DESCRIPTION . ".products_id and " . TABLE_PRODUCTS_DESCRIPTION . ".language_id = '" . (int)$languages_id . "' and " . TABLE_PRODUCTS_DESCRIPTION . ".products_name LIKE '%" . $_GET['term'] . "%'  LIMIT 0,10");
if($fetch === FALSE) {
    die(mysql_error());
}
while ($row = mysql_fetch_assoc($fetch)) 
{
   array_push($return_arr, $row['products_name']);
}  
print json_encode($return_arr);

这将返回:mysql_fetch_assoc() 参数 1 资源,在第 6 行的 ... 中给出的对象

我知道它在哪里,只是似乎无法找到问题所在。

提前致谢

4

1 回答 1

0

使用 tep_db_fetch_array()

  $return_arr = array();
  $fetch = tep_db_query("select * from products, " . TABLE_PRODUCTS_DESCRIPTION . " WHERE products.products_status = '1' and products.products_id = " . TABLE_PRODUCTS_DESCRIPTION . ".products_id and " . TABLE_PRODUCTS_DESCRIPTION . ".language_id = '" . (int)$languages_id . "' and " . TABLE_PRODUCTS_DESCRIPTION . ".products_name LIKE '%" . $_GET['term'] . "%'  LIMIT 0,10");

  echo $fetch; die;
  if($fetch === FALSE) {
      die(mysql_error());
  }
  while ($row = tep_db_fetch_array($fetch))
  {
     array_push($return_arr, $row['products_name']);
  }  
  print json_encode($return_arr);

字符串 mysqli_real_escape_string ( mysqli $link , 字符串 $escapestr )

link- mysqli_connect() 或 mysqli_init() 返回的链接标识符 escapestr- 要转义的字符串。

您可以找到一个示例http://php.net/manual/en/mysqli.real-escape-string.php第一个参数需要是 mysqli_connect() 返回的链接标识符

于 2013-09-05T11:07:31.107 回答