Re: glueDSN() function/method

From: Date: Tue, 20 Aug 2002 15:42:31 +0000
Subject: Re: glueDSN() function/method
References: 1  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-8525@lists.php.net to get a copy of this message
Ondrej Jombik wrote: > > Maxim, 17:54:58 > 19. august 2002 (pondelok) > Greetings. > > Is there somewhere in CVS repository function/method > > string glueURL(array) > > to glue parsed DSN associative array into one DSN string? I was > unable to find one. > Full untested 10 min func example: function glueDSN($d) { $dsn = $d['phptype']; $dsn .= isset($d['dbsyntax']) ? $d['dbsyntax'] : ''; $dsn .= '://'; if (isset($d['username'])) { $dsn .= $username; $dsn .= isset($d['password']) : ':' . $d['password'] : ''; $dsn .= '@'; } if (@$d['protocol'] == 'tcp')) { $dsn .= 'tcp(' . $d['hostspec']; $dsn .= isset($d['port']) ? ':' . $d['port'] : ''; $dsn .= ')'; } elseif (@$d['protocol'] == 'unix')) { $dsn .= 'unix('; $dsn .= isset($d['socket']) ? $d['socket'] : ''; $dsn .= ')'; } elseif (isset($d['hostspec'])) { $dsn .= $d['hostspec']; } $dsn .= isset($d['database']) ? '/' . $d['database'] : ''; foreach (array('dbsyntax', 'username','password','protocol', 'hostspec','port','socket','database') as $unset) unset($d[$unset]); if (count($d)) { $dsn .= '?'; foreach ($d as $k => $v) { $dsn .= "$k=$v"; } } return $dsn; } Tomas V.V.Cox

« previous php.pear.dev (#8525) next »