- 论坛徽章:
- 0
|
本帖最后由 骡子先生 于 2011-07-04 17:21 编辑
我从数据库取数据,通过tt显示,但是只能显示引用地址,请教这种情况如何处理?我的代码如下
- #!/usr/bin/perl
- use Dancer;
- use Data::Dumper;
- use DBI;
- use DBD::mysql;
- get '/sql/dbisql', sub {
- my $host = '127.0.0.1';
- my $port = '3306';
- my $dbname = 'op_system';
- my $username = 'op_system';
- my $password = 'op_system';
- my $dbh = DBI->connect("DBI:mysql:database=$dbname;host=$host;port=$port", $username, $password, {RaiseError => 1, AutoCommit => 1});
- my $sth = $dbh->prepare("select * from dataCenter");
- $sth->execute;
- my $result = $sth->fetchall_hashref('id');
- #print Dumper $result;
- template 'dbisql',
- {
- head => 'use DBI',
- content => $result,
- };
- };
- dancer;
复制代码 数据结构如下- $VAR1 = {
- '1' => {
- 'bandwidth' => undef,
- 'telephone' => '010-2343244',
- 'ip' => undef,
- 'name' => '北京三元数据中心',
- 'address' => '北京朝阳区三元桥大厦3楼',
- 'id' => '1',
- 'zipcode' => '100038'
- },
- '3' => {
- 'bandwidth' => undef,
- 'telephone' => '012-6436353',
- 'ip' => undef,
- 'name' => '天津数据中心',
- 'address' => '天津市海河区天津大厦2楼',
- 'id' => '3',
- 'zipcode' => '120003'
- },
- '2' => {
- 'bandwidth' => undef,
- 'telephone' => '021-33232432',
- 'ip' => undef,
- 'name' => '上海静安数据中心',
- 'address' => '上海市静安区发展大厦19楼',
- 'id' => '2',
- 'zipcode' => '200032'
- }
- };
复制代码 dbisql.tt- <h2><% head %></h2>
- <% FOREACH row IN content -%>
- <% row %>
- <% END %>
复制代码 显示结果- use DBI
- HASH(0x62718f0) HASH(0x6271ae0) HASH(0x6269b10)
复制代码 |
|