Quote value into Zend Framework 2

☆樱花仙子☆ 提交于 2019-12-12 00:58:35

问题


I'm working on an application using ZF2. In my application, I have to insert many rows in a database (about 900).

I've got a table model for this, so I first try to do :

$table->insert(array('x' => $x, 'y' => $y));

in my loop. This technically work, but this is so slow that I can hardly insert half of the datas before php's timeout (and I can't change the timeout).

Then, I've decide to use a prepared statment. So I've prepared it outside of the loop, then execute it in my loop... it was even slower.

So, I decide to stop using ZF2 tools, as they seems to be too slow to be used in my case, and i've created my own request. I'm using mysql, so i can do a single request with all my values. But I can't find any method in any of the interface to escape my values...

Is there any way to do this ?

Thank you for your help and sorry for my poor english.


回答1:


If you want to perform raw queries you can do so using the Database Adapter:

$sql = 'SELECT * FROM '
    . $adapter->platform->quoteIdentifier('users')
    . ' WHERE ' . $adapter->platform->quoteIdentifier('id') . ' = ' . $adapter->driver->formatParameterName('id');

/* @var $statement \Zend\Db\Adapter\Driver\StatementInterface */
$statement = $adapter->query($sql);
$parameters = array('id' => 99);

/* @var $results Zend\Db\ResultSet\ResultSet */
$results = $statement->execute($parameters);

$row = $results->current();



回答2:


use transactions: http://dev.mysql.com/doc/refman/5.0/en/commit.html Than will help you to decrease the execution time



来源:https://stackoverflow.com/questions/13287731/quote-value-into-zend-framework-2

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