<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[『AskWan』]]></title> 
<link>http://www.askwan.com/index.php</link> 
<description><![CDATA[Related About My Life,Unix,Linux,System Architecture,Mysql,PostgreSQL,Oracle Etc ]]></description> 
<language>en-US</language> 
<copyright><![CDATA[『AskWan』]]></copyright>
<item>
<link>http://www.askwan.com/use_DBD_Pg_to_connect_PostgreSQL_database/</link>
<title><![CDATA[use DBD::Pg to connect PostgreSQL database]]></title> 
<author>askwan &lt;askwan@yahoo.cn&gt;</author>
<category><![CDATA[Scripts]]></category>
<pubDate>Tue, 20 Oct 2009 02:01:50 +0000</pubDate> 
<guid>http://www.askwan.com/use_DBD_Pg_to_connect_PostgreSQL_database/</guid> 
<description>
<![CDATA[ 
	first, install&nbsp;&nbsp;DBI and DBD::Pg module<br/><br/>come next two example I have writen for testing:<br/><br/>example one:<br/><textarea name="code" class="php" rows="15" cols="100">#!/usr/bin/perl -w
#this is an example writen by askwan to insert into somedata to a table 
use DBI;


my $dbh = DBI->connect("DBI:Pg:dbname="askwan.com";host=localhost", "postgres", "postgres", {AutoCommit => 0,'RaiseError' => 1,PrintError => 1});
# The AutoCommit attribute should always be explicitly set



for(my $i=0;$i<100;$i++){
# execute INSERT query
my $rows = $dbh->do("INSERT INTO test(id, name) VALUES ('id_$i', 'name_$i')");
print "$i row(s) inserted &#92;n";
}

my $sth = $dbh->prepare("SELECT id, name FROM test");
$sth->execute();

while(my $ref = $sth->fetchrow_hashref()) {
&nbsp;&nbsp;&nbsp;&nbsp;print "$ref->{'id'} is a $ref->{'name'}&#92;n";
}

$dbh->disconnect();</textarea><br/><br/>example two:<br/><textarea name="code" class="php" rows="15" cols="100">#!/usr/bin/perl -w
#this is an example writen by askwan to query some info from PostgreSql
use DBI;

$dbname="askwan";
$host="localhost";
$port="5432";
$username="postgres";
$password="postgres";

$dbh = DBI->connect("dbi:Pg:dbname=$dbname;host=$host;port=$port;",
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$username,
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$password,
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{AutoCommit => 0, RaiseError => 1, PrintError => 0}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; );
$sth=$dbh->prepare('select datname,blks_read,blks_hit from pg_stat_database');

$sth->execute();

print sprintf("%-20s%-20s%-20s","datname","blks_read","blks_hit"),"&#92;n";
print "-" x 60 ."&#92;n";

my @data;
my ($datname,$blk_read,$blks_hit);

while(@data=$sth->fetchrow_array()) {
&nbsp;&nbsp;&nbsp;&nbsp; ($datname,$blk_read,$blks_hit)=@data;
&nbsp;&nbsp;&nbsp;&nbsp; print sprintf("%-20s%-20s%-20s","$datname","$blk_read","$blks_hit"),"&#92;n";

}
$dbh->disconnect();</textarea>output :<br/><pre>datname&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; blks_read&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; blks_hit&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&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&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 7396</pre>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br/>Tags - <a href="http://www.askwan.com/tags/%2526%2523039%253B/" rel="tag">&#039;</a> , <a href="http://www.askwan.com/tags/dbd%253Apg%2526%2523039%253Bpostgresql/" rel="tag">dbd:pg&#039;postgresql</a>
]]>
</description>
</item><item>
<link>http://www.askwan.com/use_DBD_Pg_to_connect_PostgreSQL_database/#blogcomment</link>
<title><![CDATA[[Comments] use DBD::Pg to connect PostgreSQL database]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[Comments]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>http://www.askwan.com/use_DBD_Pg_to_connect_PostgreSQL_database/#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>