有没有办法在PDO中设置默认游标类型(特别是PDO_SQLSRV)?
So, annoyingly, the PDO_SQLSRV driver from Microsoft returns -1 on any rowCount() call from a SELECT query with non-scrollable cursors.
因此,令人讨厌的是,Microsoft的PDO_SQLSRV驱动程序在来自带有不可滚动游标的SELECT查询的任何rowCount()调用时返回-1。
Further adding to the annoyance, the default cursor type is _FORWARD, meaning that I am seemingly having to add attributes to every prepared statement where I may need to get a row count back (in this app, that's A LOT) as below. This is unacceptable, as some of the database engines we will be using do not support scrollable cursors.
进一步增加烦恼,默认光标类型是_FORWARD,这意味着我似乎必须为每个准备好的语句添加属性,我可能需要返回行计数(在此应用程序中,这是很多),如下所示。这是不可接受的,因为我们将使用的一些数据库引擎不支持可滚动游标。
$pdo->prepare("SELECT x FROM y", array(PDO::ATTR_CURSOR, PDO::CURSOR_SCROLL));
Curiously this does not seem to work with PDO::query()...
奇怪的是,这似乎不适用于PDO :: query()...
Edit: As below, I've also tried PDO::setAttribute() and adding the option to PDO::__construct(), but neither throw exceptions or errors, or seem to actually do anything!
编辑:如下所示,我也尝试了PDO :: setAttribute()并将选项添加到PDO :: __ construct(),但既没有抛出异常或错误,或者似乎实际上做了什么!
My question to you all is: is there a way to set the default cursor type to CURSOR_SCROLL?
我的问题是:有没有办法将默认光标类型设置为CURSOR_SCROLL?
1 个解决方案
#1
3
What about:
$pdo->setAttribute(PDO::ATTR_CURSOR, PDO::CURSOR_SCROLL);
?
Also you can extend base PDO class with your own, with prepare
method overriden:
您也可以使用自己的扩展基础PDO类,并使用prepare方法覆盖:
class MyPdo extends PDO
{
public function prepare($statement, $options = array())
{
if (empty($options)) $options = array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL);
return parent::prepare($statement, $options);
}
}
更多相关文章
- 鼠标按下时是否可以防止鼠标光标离开页面
- 手把手教你mysql(十五)游标变量流程控制
- MYSQL存储过程,函数,光标
- SQLite的Android光标在方法调用时崩溃
- 通过不在android游标中工作的顺序
- 更改Edittext光标的颜色与粗细
- android里通过什么什么事件可以拿到由于click后的EditText的光标