如何获取 OSCommerce 查询的结果集? mysql_fetch_assoc()参数1资源、对象给定

问题描述 投票:0回答:1

我已经寻找了解决方案,并找到了几个答案,经过多次编辑代码但没有成功,我直接在这里询问。

$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 行...中给出

我明白了它在哪里,只是似乎找不到问题。

php mysql resultset oscommerce
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()返回的链接标识符

© www.soinside.com 2019 - 2024. All rights reserved.