oop - PHP PDO Database class parameter passing -
I want to set up an array with multiple parameters in it, pass it into my database class Currently I only assign one parameter I can send, but generally my SQL queries have many parameters.
  Sample database method:      Call the database method:     Now say that my SQL query was: "Choose from contacts * where CustID =? and expired?" How would I build an array and pass my function?    Every time I try, I get an array for conversion error string.    Thanks       Now to say that my SQL query was: Select "From Contacts * where CustID =? And Expired?" How will I build an array and pass my work?     I   mutiple    I personally prefer the named parameter, where I can use the associative array:   
 public function fetchQuery ($ Sql, $ params, $ conn) {try {$ queryparams = array ($ Params); $ X = $ conn- & gt; Ready ($ SQL); $ X- & gt; Execution ($ queryparams); $ RArray = $ x- & gt; Get All (PDO :: FETCH_ASSOC); Return $ Rier; } Hold (exception $ e) {die (print_r ($ e-> getMessage ())); }}    
 $ params = $ vendID; $ Sql = "Contact email where Vendid =?" Choose; {$ Email = $ db- & gt; Try Fetchquio ($ sql, $ params, $ conn); $ eCount = Count ($ email); If ($ eCount> gt;) {foreach ($ line $ email) {$ eArray [] = $ line ['email']; }} Else {resonance "email addresses not associated with this vendor"; }} Hold (exception $ e) {die (print_a ($ e-> getMessage ()); }    
 $ queryparams = array ($ params);  I will remove the part of my code, and always pass the function to an array, even if it has only one element.   
 $ params = array ($ custID); $ Sql = "Contact email where Vendid =?" Choose; {$ Email = $ db- & gt; Try Fetch Queries ($ sql, $ params, $ conn);    
 $ params = array ($ vendID, $ has expired); $ Sql = "Choose from * Contact * where CustID =? And expired?"; {$ Email = $ db- & gt; Try Fetchquio ($ sql, $ params, $ conn);   
  
 $ sql = "select * From contacts where CustID =: custId and expired =: "expired"; $ params = array (': custId' = & gt; $ custID, ': expired' = & gt; $ has expired);    
 
Comments
Post a Comment