1

Can somebody explain me where the

->setPrepareParams(array $prepareParams) 

is called in Zend\Db\Adapter\Driver\Sqlsrv\Statement.php?

Specifically, when I used this:

$this->tableGateway->select(array("Personalnummer = $personalnumber"));

It worked. But when I used this:

$this->tableGateway->select(array("Personalnummer" => $personalnumber));

It did not work.

I tried to debug this and found that the params were not being set with my second method.

Dennis
  • 7,907
  • 11
  • 65
  • 115
stefen
  • 39
  • 6

3 Answers3

0

It is a public method so it is up to the client programmer to use it.

It is just a setter for the protected property $prepareParams.

Why do you expect it to be called inside the class?

Nikitas
  • 1,013
  • 13
  • 27
  • This is my Problem: Im using: $this->tableGateway->select(array("Personalnummer = $personalnumber")); <- This is working. $this->tableGateway->select(array("Personalnummer" => $personalnumber)); <- Is not working. I tried to debug and found, that the params are not setted with second method. – stefen Mar 20 '17 at 08:41
0

Are you looking for this code?

Adapter/Driver/Sqlsrv/Statement::prepare()

Without looking deeper into it, it looks like the way you are calling the select statement, it expects indices that are numbers: 0, 1, 2, 3, ... and so on.

So when you call

array("Personalnummer = $personalnumber")

It is the same as calling

array(0 => "Personalnummer = $personalnumber")

And since code expects a value at index 0, your code works then. When you use parameterized statements, your code fails. Because it does not expect parameterized arrays (your second way).

Look into how you set your initial parameters. There may be a configuration option that sets the code to expect parameterized arrays.

Dennis
  • 7,907
  • 11
  • 65
  • 115
  • Thank you. My problem is, that I want to use the array("Personalnummer" => $personalnumber) Method, because then the parameters are quoted. It should be working(Zend Tutorial), but it doesnt. I tried to find out where the parameters are setted but only found the part where the column-Name is setted. Can you may explain me where the parameter-value is setted. They are alway empty :/ Configuration should be ok, because this method is working: array("Personalnummer = $personalnumber") – stefen Mar 31 '17 at 15:47
  • do you have a link to the tutorial page where it should be working? – Dennis Mar 31 '17 at 16:06
  • by the way it looks to me like SQL Server driver that Zend uses does not have the syntax of parameter-value arrays. If you look at the code I have linked, it passes `''` (emtpy value) when it should be passing an actual value. In other words, SQL Server driver that Zend has will not do what you want. You will have to use the integer-indexed array, without parameter-values – Dennis Mar 31 '17 at 19:17
0

In your database configuration, what is your connection driver? PHP supports parameterized queries only through PDO, and Zend Framework cannot go beyond what PHP is capable of. Therefore, to get array("Personalnummer" => $personalnumber) to work, you need to have configuration driver key be pdo_sqlsrv. Sounds like you have 'driver' => 'Sqlsrv' instead.

alex-tech
  • 397
  • 2
  • 14