Zend framework 扩展Zend_-Db
我很抱歉,如果我的标题有点误导,并且它是Zend framework 扩展Zend_-Db,zend-framework,zend-db,Zend Framework,Zend Db,我很抱歉,如果我的标题有点误导,并且它是Zend_Db下的其他类 我使用以下方法从MSSQL中提取数据: // $_config contains information about how to connect to my MSSQL server $config = new Zend_Config($_config); $db = Zend_Db::factory($config->database); $sql = "SELECT * FROM table1"; print_r($
Zend_Db
下的其他类
我使用以下方法从MSSQL中提取数据:
// $_config contains information about how to connect to my MSSQL server
$config = new Zend_Config($_config);
$db = Zend_Db::factory($config->database);
$sql = "SELECT * FROM table1";
print_r($db->fetchAll($sql));
到目前为止没有问题,一切都很顺利:)
现在,我需要使用多个行集运行一些更复杂的查询:
$sql2 = <<<EOD
DECLARE @test INT
SET @test = 42
SELECT * FROM table1 WHERE col1 = @test
SELECT col2 FROM table2 UNION
SELECT col3 FROM table2
SELECT * FROM table3
EOD;
print_r($db->fetchAll($sql2));
现在我的大问题是:
如何扩展Zend_Db
,以便实现和使用上面的函数作为$Db->fetchMulti($sql2)
而不是sqlquery\u multiple($db,$sql2)
提前感谢:)
注意:值得一提的是,我首先使用是为了能够获取多个行集。不确定答案,但您确实扩展了Zend_Db_适配器,而不是Zend_Db;)我有一种感觉,它不会是Zend_Db。你是说它肯定是Zend_Db_Adapter,还是说它可能是其他东西?我也发现了一些扩展
Zend_Db_Abstract
的例子,但我不确定从哪一个开始:(。
function sqlquery_multiple($zdb, $sql) {
$stmt = $zdb->query($sql);
$rowsets = array();
do {
if ($stmt->columnCount() > 0) {
$rowsets[] = $stmt->fetchAll(PDO::FETCH_ASSOC);
}
} while ($stmt->nextRowset());
return $rowsets;
}
print_r(sqlquery_multiple($db, $sql2));