php - DB2 error Improper use of a string column, host variable, constant, or function -
i'm trying search tables , columns value , i'm using php connection ibm db2 database. wondering if error cause because of multiple usage of union.
this error message :
improper use of string column, host variable, constant, or function "namabarang". sqlstate=42907 sqlcode=-134
and here code :
$keyword=$_get['keyword']; $query="select * inventory namabarang '%".$keyword."%'". " union select * inventory arrivaldate '%".$keyword."%'". " union select * inventory papernumber '%".$keyword."%'". " union select * inventory serialnumber '%".$keyword."%'". " union select * inventory condition '%".$keyword."%'". " union select * inventory location '%".$keyword."%'". " union select * inventory confirmationdate '%".$keyword."%'". " union select * inventory barcode '%".$keyword."%'". " union select * userandpassword username '%".$keyword."%'"; " union select * userandpassword access '%".$keyword."%'";
see info on error message here. problem appears namabarang
1 of long character/clob types, , illegal have in query performs grouping. query performs grouping because 1 of sub-queries uses union
rather union all
. union
groups when removes duplicate rows.
a query should not return columns (select *
). instead, return need. possibly id column can identify each row matched, , name of column , table matched. remove error.
a few other points:
- your code unsafe! taking parameter directly form , inserting sql. can use sorts of evil things, delete tables database. please take @ the first answer question safe way of using user-entered data in queries.
- you unioning rows 2 different tables
userandpassword
have exact same columnsinventory
? if not, union not work. solves not selecting*
, instead select similar set of columns each table. - union or union all? want return multiple matches single row if more 1 column contains search string? if so, use
union all
. otherwise, useunion
remove duplicates.
Comments
Post a Comment