niche Posted October 6, 2018 Share Posted October 6, 2018 (edited) This code works, but can someone tell me how I can use an array instead of bindParam in this situation. try { $sql = ' SELECT * FROM nconnectz WHERE itemandsize LIKE :itemandsize AND price > 0 ORDER BY price ASC '; $stmt2 = $db2->prepare($sql); } catch (PDOException $e) { echo $e->getMessage() . '<br>'; } $var = "%Flour%"; try { $stmt2->bindParam(':itemandsize',$var); $stmt2->execute(); } catch (PDOException $e) { echo $e->getMessage() . '<br>'; } Something like? $stmt2->execute(array( :itemandsize => '%Flour%' )); Edited October 6, 2018 by niche Link to comment Share on other sites More sharing options...
niche Posted October 6, 2018 Author Share Posted October 6, 2018 Interesting. When I strip-out all the white space it works: $stmt2->execute(array(':itemandsize' => '%' . $var . '%')); I've heard of white space being a problem, but haven't knowingly experienced it. Any thoughts? Urban legend? Link to comment Share on other sites More sharing options...
Ingolme Posted October 6, 2018 Share Posted October 6, 2018 There's no problem with whitespace in the code itself. What I do find is that in your first post, you forgot to quote :itemandsize string. Link to comment Share on other sites More sharing options...
niche Posted October 6, 2018 Author Share Posted October 6, 2018 Voila! Thanks for your help. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now