0

I want to insert 5 llines in my db, however the following

$qry = $db->prepare('INSERT IGNORE INTO table (foo, bar) VALUES (?,?), (?,?), (?,?), (?,?), (?,?)'); $qry->execute(array( array($foo1, $bar), array($foo2, $bar), array($foo3, $bar), array($foo4, $bar), array($foo5, $bar) )); 

gives me this error

Warning: PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens 

What should I do to make it work ?

1 Answer 1

1

Remove the extra arrays in the execute()

$qry = $db->prepare('INSERT IGNORE INTO table (foo, bar) VALUES (?,?), (?,?), (?,?), (?,?), (?,?)'); $qry->execute(array( $foo1, $bar, $foo2, $bar, $foo3, $bar, $foo4, $bar, $foo5, $bar )); 
Sign up to request clarification or add additional context in comments.

1 Comment

Oh god... I also tried this (which gave me another error that I thought I fixed with the arrays) : $qry->execute(array( ($foo1, $bar), ($foo2, $bar), ($foo3, $bar), ($foo4, $bar), ($foo5, $bar) ));... (parenthesis added over each "$foo1, $bar" line). PHP is driving me mad. Thank you !

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.