-1

I think I've read many topics on that question but still get a wrong result. I have a query parameters array that I want to loop with foreach() to bind parameters.

foreach($aQueryParams as $key => &$value){
    $stmt->bindParam($key, $value);
}

This concerns an INSERT query and what I get as a result is the key inserted in my table instead of the value. But I'm sure that the key and the value are good and at the good place. A var_dump() on $key and $value give :firstName for the $key and Samy for the &$value. But this is :firstName that is inserted in my table...

And I also tried with a bindValue without using the reference and it's the same result.

To be clearer, I give you the link of the gitHub repository. You can see the declaration of the parameters array in ClientManager.class.php at line 44, and the foreach() loop to bind parameters in DBOperation.class.php at line 97. https://github.com/code-climber/car_rental/blob/preparedStmt/src/car_rental/model/dao/ClientManager.class.php

I'm going mad with this.

Samy-DT
  • 13
  • 5
  • Since I can't see the rest of your code, I'm assuming it's a duplicate of this: http://stackoverflow.com/questions/3307409/php-pass-by-reference-in-foreach. If not, what exactly are you trying to accomplish with the reference? – Mike Sep 29 '15 at 22:49
  • Why not just bind the parameters with an array in the `execute()`? I find it much less of a hassle personally. – Rasclatt Sep 30 '15 at 00:42
  • Mike, I don't think it's a duplicate because I only have one foreach() loop. What I'm trying to accomplish is simple. My array of parameters is like ':login'=>'Samy', and I want to insert 'Samy', the value, in my table, but for now, this is ':login', the key, which is inserted. Rasclatt, can you give an example, because for now, I always see people binding parameters outside the execute(). I edit my post with a gitHub link to this code. – Samy-DT Sep 30 '15 at 06:59

1 Answers1

0

Ok, I finally found what was wrong. This was my SQL query. I had put some quotes around each VALUES parameters. As I did not have error message, I focused only on the thing which was new to me, the loop over the bindParam().

I find the moderator a bit severe about the clarity of my question because I really read all I can on the reference...It was not a duplicate. The error was elsewhere.

Samy-DT
  • 13
  • 5