Zend 2: SQLSRV: $prepareParams is not being set

老子叫甜甜 提交于 2019-12-20 04:26:14

问题


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.


回答1:


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?




回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/42859322/zend-2-sqlsrv-prepareparams-is-not-being-set

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!