Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我在我的代码中创建了这个函数:
function fetch() { return fetch(PDO::FETCH_OBJ) }
只做
$query->fetch()
它会自动变成
$query->fetch(PDO::FETCH_OBJ)
但它似乎不起作用。正确的方法是什么?
设置PDO::FETCH_OBJ默认使用的数据库连接:
PDO::FETCH_OBJ
$db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ);
该函数不起作用,因为您不能在 PHP 中扩展现有的类(好吧,没有 RunKit 黑客)。
将查询作为参数添加到函数中:
<?php function fetch($q) { return $q->fetch(PDO::FETCH_OBJ) } fetch($query); ?>