Re: extra spaces

From: Date: Tue, 19 Dec 2000 23:35:01 +0000
Subject: Re: extra spaces
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-5349@lists.php.net to get a copy of this message
> > Soma> All values called from the database are still padded with > > Soma> extra spaces from the column size in the database. Is this > > Soma> normal - I don't remember this happening when I was using > > Soma> MySQL. I thought usually the database stripped the extra > > Soma> spaces when it retrieved the values. > > According to "Postgres: Introduction and Concepts", varchar is slower > than char. So if you (like me) want to use char and get rid of the > padding spaces, you may use a regex replacement, as in > > while (@row=$result->fetchrow) > { > $row[0] =~ s/[\s]+$//; > } > > in perl, or > > $array["name"]=preg_replace("'[\s]+$'", "", > $array["name"], -1); > > in PHP. > I'm new to the list so I'm not sure if this has already been said, but Perl DBI has an option to trim trailing spaces in the connect statement. eg: my $dbh = DBI->connect("dbi:Pg:dbname=mydb", 'myuser','mypass', {RaiseError => 1, AutoCommit => 0, ChopBlanks => 1}) or die $DBI::errstr; Cheers

« previous php.db (#5349) next »