$select = new Select();
$select ->from(array('h' => 'hotels'),
array('*'))
->join(array('t' => 'roomtypes'),
'h.id = t.hotel_id')
->join(array('c' => 'roomcapacities'),
'c.roomtype_id = t.id')
->where('h.country = '.$country_code )
->where('h.state = '.$state)
->where('h.city = '.$city)
->where('c.no_of_adult = '.$adults);
print $select->getSqlString();
$rowset = new DbSelect( $select , $this->tableGateway->getAdapter() );
我是zend框架的新手。我想从这三个表中透露数据。但是我无法获得此连接查询的正确结果。我在哪里做错了?请帮帮我
如何从此结果集中获取字段?我在查询上方得到了这个结果表单。
SELECT "h".*, "t".*, "c".* FROM "hotels" AS "h" INNER JOIN "roomtypes" AS "t" ON "h"."id" = "t"."hotel_id" INNER JOIN "roomcapacities" AS "c" ON "c"."roomtype_id" = "t"."id" WHERE h.country = USA AND h.state = usas2 AND h.city = usac1 AND c.no_of_adult = 3Zend\Paginator\Adapter\DbSelect Object
(
[sql:protected] => Zend\Db\Sql\Sql Object
(
[adapter:protected] => Zend\Db\Adapter\Adapter Object
(
[driver:protected] => Zend\Db\Adapter\Driver\Pdo\Pdo Object
(
[connection:protected] => Zend\Db\Adapter\Driver\Pdo\Connection Object
(
[driver:protected] => Zend\Db\Adapter\Driver\Pdo\Pdo Object
*RECURSION*
[profiler:protected] =>
[driverName:protected] => mysql
[connectionParameters:protected] => Array
(
[driver] => pdo_mysql
[dsn] => mysql:dbname=tour_management_system;host=localhost
[driver_options] => Array
(
[1002] => SET NAMES 'UTF8'
[1000] => 1
)
[username] => root
[password] =>
)
[resource:protected] =>
[inTransaction:protected] =>
)
[statementPrototype:protected] => Zend\Db\Adapter\Driver\Pdo\Statement Object
(
[pdo:protected] =>
[profiler:protected] =>
[driver:protected] => Zend\Db\Adapter\Driver\Pdo\Pdo Object
*RECURSION*
[sql:protected] =>
[isQuery:protected] =>
[parameterContainer:protected] =>
[parametersBound:protected] =>
[resource:protected] =>
[isPrepared:protected] =>
)
[resultPrototype:protected] => Zend\Db\Adapter\Driver\Pdo\Result Object
(
[statementMode:protected] => forward
[resource:protected] =>
[options:protected] =>
[currentComplete:protected] =>
[currentData:protected] =>
[position:protected] => -1
[generatedValue:protected] =>
[rowCount:protected] =>
)
[features:protected] => Array
(
)
)
[platform:protected] => Zend\Db\Adapter\Platform\Mysql Object
(
[resource:protected] => Zend\Db\Adapter\Driver\Pdo\Pdo Object
(
[connection:protected] => Zend\Db\Adapter\Driver\Pdo\Connection Object
(
[driver:protected] => Zend\Db\Adapter\Driver\Pdo\Pdo Object
*RECURSION*
[profiler:protected] =>
[driverName:protected] => mysql
[connectionParameters:protected] => Array
(
[driver] => pdo_mysql
[dsn] => mysql:dbname=tour_management_system;host=localhost
[driver_options] => Array
(
[1002] => SET NAMES 'UTF8'
[1000] => 1
)
[username] => root
[password] =>
)
[resource:protected] =>
[inTransaction:protected] =>
)
[statementPrototype:protected] => Zend\Db\Adapter\Driver\Pdo\Statement Object
(
[pdo:protected] =>
[profiler:protected] =>
[driver:protected] => Zend\Db\Adapter\Driver\Pdo\Pdo Object
*RECURSION*
[sql:protected] =>
[isQuery:protected] =>
[parameterContainer:protected] =>
[parametersBound:protected] =>
[resource:protected] =>
[isPrepared:protected] =>
)
[resultPrototype:protected] => Zend\Db\Adapter\Driver\Pdo\Result Object
(
[statementMode:protected] => forward
[resource:protected] =>
[options:protected] =>
[currentComplete:protected] =>
[currentData:protected] =>
[position:protected] => -1
[generatedValue:protected] =>
[rowCount:protected] =>
)
[features:protected] => Array
(
)
)
)
[profiler:protected] =>
[queryResultSetPrototype:protected] => Zend\Db\ResultSet\ResultSet Object
(
[allowedReturnTypes:protected] => Array
(
[0] => arrayobject
[1] => array
)
[arrayObjectPrototype:protected] => ArrayObject Object
(
[storage:ArrayObject:private] => Array
(
)
)
[returnType:protected] => arrayobject
[buffer:protected] =>
[count:protected] =>
[dataSource:protected] =>
[fieldCount:protected] =>
[position:protected] => 0
)
[lastPreparedStatement:protected] =>
)
[table:protected] =>
[sqlPlatform:protected] => Zend\Db\Sql\Platform\Platform Object
(
[adapter:protected] => Zend\Db\Adapter\Adapter Object
(
[driver:protected] => Zend\Db\Adapter\Driver\Pdo\Pdo Object
(
[connection:protected] => Zend\Db\Adapter\Driver\Pdo\Connection Object
(
[driver:protected] => Zend\Db\Adapter\Driver\Pdo\Pdo Object
*RECURSION*
[profiler:protected] =>
[driverName:protected] => mysql
[connectionParameters:protected] => Array
(
[driver] => pdo_mysql
[dsn] => mysql:dbname=tour_management_system;host=localhost
[driver_options] => Array
(
[1002] => SET NAMES 'UTF8'
[1000] => 1
)
[username] => root
[password] =>
)
[resource:protected] =>
[inTransaction:protected] =>
)
....
)
答案 0 :(得分:0)
要获得结果,请执行以下操作:
$results = $select->query()->fetchAll();
请注意,查询函数返回Zend_Db_Statement对象。根据应用于数据库适配器的提取模式,您将获得一个数组或一组对象或两者作为结果。要更改获取模式,请使用以下代码:
$this->tableGateway->getAdapter()->setFetchMode([fetch mode])
其中fetch模式的可能值被枚举enter link description here。
答案 1 :(得分:0)
我解决了这个问题。
$resultSet = $this->tableGateway->select(function (Select $select) use($where) {
$select->columns(array());
$select->join(array('h' => 'hotels'),'h.id = roomtypes.hotel_id',array("id","hotel_code"));
return $resultSet->buffer();
它提供了所需的输出。