gpt4 book ai didi

mysql - 连接查询结果显示出现问题

转载 作者:行者123 更新时间:2023-11-30 00:49:06 25 4
gpt4 key购买 nike

$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] =>
)
....
)

最佳答案

要获取结果,请执行以下操作:

$results = $select->query()->fetchAll();

请注意,查询函数返回一个 Zend_Db_Statement 对象。根据应用于数据库适配器的获取模式,您将获得一个数组或一个对象数组或两者作为结果。要更改获取模式,请使用以下代码:

$this->tableGateway->getAdapter()->setFetchMode([fetch mode])

其中枚举了获取模式的可能值 enter link description here .

关于mysql - 连接查询结果显示出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21134201/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com