mySQL parameter passing problem

43 views
Skip to first unread message

HarryB

unread,
Jul 20, 2018, 4:02:49 AM7/20/18
to Fat-Free Framework
Greetings all,

I have made great progress with my project but I have now struck a problem that has me stumped.  It involves passing an array of values to an UPDATE query.

Here is the string that is being passed to the exec function (from the error report) split up to make it more compact rather than one long line:

DB\SQL->exec(['UPDATE eclectic SET 1st = ?, 2nd = ?, 3rd = ?, 4th = ?, 5th = ?, 6th = ?, 7th = ?, 8th = ?, 9th = ?, 10th = ?,
 11th = ?, 12th = ?, 13th = ?, 14th = ?, 15th = ?, 16th = ?, 17th = ?, 18th = ?, Total = ?, ID = ?
WHERE Player_Initials = 'BOUH''],[[[1=>'4',2=>'5',3=>'3',4=>'3',5=>'4',6=>'5',7=>'3',8=>'3',9=>'4',10=>'4',11=>'3',12=>'2',
13=>'5',14=>'4',15=>'3',16=>'4',17=>'4',18=>'3',19=>'66',20=>'0']]])

I am a bit nonplussed about the number of square brackets around the data array and if you think this is the problem can
you guide as to how to reduce/eliminate them.

The failure error is: Invalid parameter number: number of bound variables does not match number of tokens

The variable count does match the number of tokens (as far as I can see) which is why I wonder about the number of sets of brackets.

This is the code in the 'model':

public function updateEclectic($buildSQL,$playerinits,$updata) {
return $this->db->exec("UPDATE eclectic SET $buildSQL WHERE Player_Initials = '$playerinits'", array($updata));
}

Thanks in anticipation.

Harry

ved

unread,
Jul 20, 2018, 5:15:52 AM7/20/18
to Fat-Free Framework
Hi,
Why are you nesting the arguments in a 3 level array?

[[[1=>'4',2=>'5',3=>'3',4=>'3',5=>'4',6=>'5',7=>'3',8=>'3',9=>'4',10=>'4',11=>'3',12=>'2',
13=>'5',14=>'4',15=>'3',16=>'4',17=>'4',18=>'3',19=>'66',20=>'0']]]

It should probably be:

[1=>'4',2=>'5',3=>'3',4=>'3',5=>'4',6=>'5',7=>'3',8=>'3',9=>'4',10=>'4',11=>'3',12=>'2',
13=>'5',14=>'4',15=>'3',16=>'4',17=>'4',18=>'3',19=>'66',20=>'0']

Unless I'm missing something

HarryB

unread,
Jul 21, 2018, 9:38:23 PM7/21/18
to Fat-Free Framework
Thank you ved,

 The problem was that I was passing an array and then I had it inside another array wrapper in the query. Once that was taken out it all worked fine.

I might have worked it out eventually but your comment turned on the light bulb.

Thanks again.

Harry
Reply all
Reply to author
Forward
0 new messages