开发者

Need example of binding LIKE DB2 statements in PHP

开发者 https://www.devze.com 2023-03-14 17:32 出处:网络
I am trying to do something similar to this... $sql = \"SELECT * FROM foo WHERE user = ? AND order LIKE ?%\"

I am trying to do something similar to this...

$sql = "SELECT * FROM foo WHERE user = ? AND order LIKE ?%"
$stmt = db2_prepare($conn, $sql);

db2_bind_param($stmt, 1, "userName", DB2_PARAM_IN);
db2_bind_param($stmt, 2, "orderNum", DB2_PARAM_IN);

db2_execute($stmt);

Of course, its not the right way to do LIKE ?%. I'm just l开发者_Go百科ooking for the correct way to bind a parameter like that but also use the % wildcard.


Just stick the parameter with the wildcard characters in the string. You'll want to do something like (see example #12):

$sql = "SELECT * FROM foo WHERE user = ? AND order LIKE ?"

and

$orderNum = '%' . $your_order_num . '%';
db2_bind_param($stmt, 2, "orderNum", DB2_PARAM_IN);
0

精彩评论

暂无评论...
验证码 换一张
取 消