有人可以建议我我的代码有什么问题吗?尽管 insert(),update()和delete() 都可以正常工作。这是我在Zend框架上的第一个项目,过去两天我一直在搞弄它,却没有弄清它到底出了什么问题。我正在使用Zend Framework 1。
这是我的功能主体。
public function getMenuCategoryById(Application_Model_MenuCategories $MenuCategory) {
$where = array(
'mc_id' => (int) $MenuCategory->__get('mc_id')
);
$result = $this->_db_table->find($where);
echo '<pre';
print_r($result);
die();
if (count($result) == 0) {
return false;
}
$row = $result->current();
$menuCategory = new Application_Model_MenuCategories($row);
return $menuCategory;
}
这不返回行。相反,它会提供 Zend_Db_Table_Rowset对象,如下所示:
Zend_Db_Table_Rowset Object (
[_data:protected] => Array
(
)
[_table:protected] => Application_Model_DbTable_MenuCategories Object
(
[_name:protected] => menu_categories
[_definition:protected] =>
[_definitionConfigName:protected] =>
[_db:protected] => Zend_Db_Adapter_Pdo_Mysql Object
(
[_pdoType:protected] => mysql
[_numericDataTypes:protected] => Array
(
[0] => 0
[1] => 1
[2] => 2
[INT] => 0
[INTEGER] => 0
[MEDIUMINT] => 0
[SMALLINT] => 0
[TINYINT] => 0
[BIGINT] => 1
[SERIAL] => 1
[DEC] => 2
[DECIMAL] => 2
[DOUBLE] => 2
[DOUBLE PRECISION] => 2
[FIXED] => 2
[FLOAT] => 2
)
[_defaultStmtClass:protected] => Zend_Db_Statement_Pdo
[_config:protected] => Array
(
[dbname] => test_db
[host] => localhost
[username] => root
[password] => Password@123
[charset] =>
[persistent] =>
[options] => Array
(
[caseFolding] => 0
[autoQuoteIdentifiers] => 1
[fetchMode] => 2
)
[driver_options] => Array
(
)
)
[_fetchMode:protected] => 2
[_profiler:protected] => Zend_Db_Profiler Object
(
[_queryProfiles:protected] => Array
(
)
[_enabled:protected] =>
[_filterElapsedSecs:protected] =>
[_filterTypes:protected] =>
)
[_defaultProfilerClass:protected] => Zend_Db_Profiler
[_connection:protected] => PDO Object
(
)
[_caseFolding:protected] => 0
[_autoQuoteIdentifiers:protected] => 1
[_allowSerialization:protected] => 1
[_autoReconnectOnUnserialize:protected] =>
)
[_schema:protected] =>
[_cols:protected] => Array
(
[0] => mc_id
[1] => category_name
)
[_primary:protected] => Array
(
[1] => mc_id
)
[_identity:protected] => 1
[_sequence:protected] => 1
[_metadata:protected] => Array
(
[mc_id] => Array
(
[SCHEMA_NAME] =>
[TABLE_NAME] => menu_categories
[COLUMN_NAME] => mc_id
[COLUMN_POSITION] => 1
[DATA_TYPE] => int
[DEFAULT] =>
[NULLABLE] =>
[LENGTH] =>
[SCALE] =>
[PRECISION] =>
[UNSIGNED] =>
[PRIMARY] => 1
[PRIMARY_POSITION] => 1
[IDENTITY] => 1
)
[category_name] => Array
(
[SCHEMA_NAME] =>
[TABLE_NAME] => menu_categories
[COLUMN_NAME] => category_name
[COLUMN_POSITION] => 2
[DATA_TYPE] => varchar
[DEFAULT] =>
[NULLABLE] =>
[LENGTH] => 255
[SCALE] =>
[PRECISION] =>
[UNSIGNED] =>
[PRIMARY] =>
[PRIMARY_POSITION] =>
[IDENTITY] =>
)
)
[_metadataCache:protected] =>
[_metadataCacheInClass:protected] => 1
[_rowClass:protected] => Zend_Db_Table_Row
[_rowsetClass:protected] => Zend_Db_Table_Rowset
[_referenceMap:protected] => Array
(
)
[_dependentTables:protected] => Array
(
)
[_defaultSource:protected] => defaultNone
[_defaultValues:protected] => Array
(
)
)
[_connected:protected] => 1
[_tableClass:protected] => Application_Model_DbTable_MenuCategories
[_rowClass:protected] => Zend_Db_Table_Row
[_pointer:protected] => 0
[_count:protected] => 0
[_rows:protected] => Array
(
)
[_stored:protected] => 1
[_readOnly:protected] => )
答案 0 :(得分:1)
一切正常-fetchAll()返回Zend_Db_Table_Rowset对象。您可以直接对其进行迭代:
foreach($result as $row) {
// $row is Zend_Db_Table_Row object
}
或转换为数组:
$arrayResult = $result->toArray();
但是,转储$result
显示查询与表中的任何行都不匹配-请检查您的$where
条件。