$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] =>
)
....
)
什么结果是正确的? – voodoo417
为什么这个标记为mysql – Strawberry
任何人都可以请给我正确的方式来执行此查询? –