Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Zend_Db对Db行而不是数组的自定义查询_Php_Zend Framework_Zend Db_Zend Db Table - Fatal编程技术网

Php Zend_Db对Db行而不是数组的自定义查询

Php Zend_Db对Db行而不是数组的自定义查询,php,zend-framework,zend-db,zend-db-table,Php,Zend Framework,Zend Db,Zend Db Table,在DbTable上调用fetchAll()时,我会在DbTable中定义的适当DbRow类中获得结果 但当我创建这样的自定义查询时,我会在数组中得到结果。是否有任何参数可以强制在DbRows中接收此数据,或者我应该自己创建行并用这些数组填充它们 $query = $this->_dbTable->getDefaultAdapter()->select() ->from('doctor.doctor') ->joinInner('fac

在DbTable上调用fetchAll()时,我会在DbTable中定义的适当DbRow类中获得结果

但当我创建这样的自定义查询时,我会在数组中得到结果。是否有任何参数可以强制在DbRows中接收此数据,或者我应该自己创建行并用这些数组填充它们

$query = $this->_dbTable->getDefaultAdapter()->select()
        ->from('doctor.doctor')
        ->joinInner('facility.doctorfacility', 'facility.doctorfacility.doctor_id = doctor.doctor.id')
        ->joinInner('facility.facility', 'facility.doctorfacility.facility_id = facility.facility.id')
        ->where(implode(' AND ', $conds));

return $this->_dbTable->getDefaultAdapter()->fetchAll($query);

您不能强制它,因为数据将来自多个表,所以zend_db不可能进行映射。它留给我们将数据映射到实体

如果需要对象数组,则可以更改获取模式

Zend_Db::FETCH_OBJ:返回对象数组中的数据。默认值 类是PHP内置的类stdClass。结果集的列 作为对象的公共属性提供

供参考:


某些框架类似于原则,允许我们提供mapper,在这里我们可以传递自定义mapper对象

您不能强制它,因为数据将来自多个表,所以zend_db不可能进行映射。它留给我们将数据映射到实体

如果需要对象数组,则可以更改获取模式

Zend_Db::FETCH_OBJ:返回对象数组中的数据。默认值 类是PHP内置的类stdClass。结果集的列 作为对象的公共属性提供

供参考:

某些框架类似于原则,允许我们提供mapper,在这里我们可以传递自定义mapper对象

“但当我创建这样的自定义查询时,我会在数组中得到结果”

获取数组是因为调用
Zend\u Db\u Adapter\u Abstract::fetchAll()
,根据代码中的docblock返回数组:-

/**
 * Fetches all SQL result rows as a sequential array.
 * Uses the current fetchMode for the adapter.
 *
 * @param string|Zend_Db_Select $sql  An SQL SELECT statement.
 * @param mixed                 $bind Data to bind into SELECT placeholders.
 * @param mixed                 $fetchMode Override current fetch mode.
 * @return array
 */
public function fetchAll($sql, $bind = array(), $fetchMode = null)
“在DbTable上调用fetchAll()时,我会在DbTable中定义的正确DbRow类中获得结果。”

执行此操作时,将调用
Zend\u Db\u Table\u Abstract::fetchAll()
,根据代码中的docblock,它将返回一个
Zend\u Db\u Table\u行集
:-

/**
 * Fetches all rows.
 *
 * Honors the Zend_Db_Adapter fetch mode.
 *
 * @param string|array|Zend_Db_Table_Select $where  OPTIONAL An SQL WHERE clause or Zend_Db_Table_Select object.
 * @param string|array                      $order  OPTIONAL An SQL ORDER clause.
 * @param int                               $count  OPTIONAL An SQL LIMIT count.
 * @param int                               $offset OPTIONAL An SQL LIMIT offset.
 * @return Zend_Db_Table_Rowset_Abstract The row results per the Zend_Db_Adapter fetch mode.
 */
public function fetchAll($where = null, $order = null, $count = null, $offset = null)
“是否有任何参数可以强制在DbRows中接收此数据,或者我应该自己创建行并用这些数组填充它们?”

不,没有,但是如果对正确的对象调用正确的方法,将返回行集

要执行此操作,请更改此行:-

$query = $this->_dbTable->getDefaultAdapter()->select()
return $this->_dbTable->getDefaultAdapter()->fetchAll($query);
致:-

这一行的一个例子是:-

$query = $this->_dbTable->getDefaultAdapter()->select()
return $this->_dbTable->getDefaultAdapter()->fetchAll($query);
致:-

这应该能满足你的需要。如果您被困在ZF中,那么查看代码总是值得的,它是迄今为止最好的可用文档

“但当我创建这样的自定义查询时,我会在数组中得到结果”

获取数组是因为调用
Zend\u Db\u Adapter\u Abstract::fetchAll()
,根据代码中的docblock返回数组:-

/**
 * Fetches all SQL result rows as a sequential array.
 * Uses the current fetchMode for the adapter.
 *
 * @param string|Zend_Db_Select $sql  An SQL SELECT statement.
 * @param mixed                 $bind Data to bind into SELECT placeholders.
 * @param mixed                 $fetchMode Override current fetch mode.
 * @return array
 */
public function fetchAll($sql, $bind = array(), $fetchMode = null)
“在DbTable上调用fetchAll()时,我会在DbTable中定义的正确DbRow类中获得结果。”

执行此操作时,将调用
Zend\u Db\u Table\u Abstract::fetchAll()
,根据代码中的docblock,它将返回一个
Zend\u Db\u Table\u行集
:-

/**
 * Fetches all rows.
 *
 * Honors the Zend_Db_Adapter fetch mode.
 *
 * @param string|array|Zend_Db_Table_Select $where  OPTIONAL An SQL WHERE clause or Zend_Db_Table_Select object.
 * @param string|array                      $order  OPTIONAL An SQL ORDER clause.
 * @param int                               $count  OPTIONAL An SQL LIMIT count.
 * @param int                               $offset OPTIONAL An SQL LIMIT offset.
 * @return Zend_Db_Table_Rowset_Abstract The row results per the Zend_Db_Adapter fetch mode.
 */
public function fetchAll($where = null, $order = null, $count = null, $offset = null)
“是否有任何参数可以强制在DbRows中接收此数据,或者我应该自己创建行并用这些数组填充它们?”

不,没有,但是如果对正确的对象调用正确的方法,将返回行集

要执行此操作,请更改此行:-

$query = $this->_dbTable->getDefaultAdapter()->select()
return $this->_dbTable->getDefaultAdapter()->fetchAll($query);
致:-

这一行的一个例子是:-

$query = $this->_dbTable->getDefaultAdapter()->select()
return $this->_dbTable->getDefaultAdapter()->fetchAll($query);
致:-


这应该能满足你的需要。如果您被困在ZF中,那么代码总是值得一看的,它是迄今为止最好的文档。

但我只需要医生表的数据。联接用于过滤行,但我想如果我只在第二个参数中精确定义医生表列,它不会改变,但我只需要医生表的数据。联接用于过滤行,但我想,如果我只从第二个参数中精确地输入doctor表列,它不会改变。更改后,我得到的是数组的行集,而不是DbRows。我还必须将完整性检查设置为false。最后,我要的是zend中的posible吗?在更改之后,我得到了数组的行集,而不是DbRows。我还必须将完整性检查设置为false。那么,我在zend的最终要求是什么呢?