I am trying to create a method in PHP, which dynamically binds to a PDO query quote. Unfortunately, in my code below, I can bind only 1 parameter, because adding more parameters will override the previous parameters. Still, is there a good way to fix this problem?
I hope someone can help you thanks!
Function Exporter ($ query, $ critArr = null) {$ rows = array (); {$ Stmt = $ this- & gt; Pdo- & gt; Prepare ($ query); If (! $ CritArr) {foreach ($ critKrr $ cKey => $ cValue) {$ stmt-> gt; BindParam ($ cKey, $ cValue); // !! }} $ Stmt-> carry about ();
You do not need to do this. already takes an array of parameters function execution ($ query, $ critArr = null) {$ rows = array (); {$ Stmt = $ this- & gt; Pdo- & gt; Prepare ($ query); $ Stmt- & gt; Execution ($ critArr); // ... The basic problem is that the reference works by, and foreach rather than repeating the same variable instead of repeating them Make loop and (re) them on the top You were effectively binding on the same variable and again (by coincidence, this is the problem that is the mysqli extension, whereas it has convenient pre-layout -a execute method lacks.)
Comments
Post a Comment