Hi, As Alex asked me why I not giving the name of the database in the connection string, the script I writing is basically a testing scripting.It will connect to the database engine then iterate over all the database available.If the database of my interest is available I will connect to it.Else I will thrown an error.
Simple solution what I thought is giving the database name in connection string.If the connection is not successful, then it is clear the database is not there.But What if there is ten or fifteen db I have to check for.I dont want to hardcode for all the database.I want to have a generalised solution. John, the code provided by you is for Mysql.I actually struck with sql server.When I slightly modified your code for sql server.I got the same error "selectdb()" cannot be found. Please help me with this. Thanks & Regards, Manikandan.G On Fri, May 14, 2010 at 8:50 PM, John Scoles <sco...@pythian.com> wrote: > Alexander Foken wrote: > >> On 13.05.2010 16:58, mani kandan wrote: >> >>> Hi Tim, >>> >>> I wrote a small script that connect to SQL Server engine.I don't want to >>> give the name of the databse in the connection string. >>> >> Why not? >> >> >>> I want to select a db >>> on the fly only if it present. >>> >> When WHAT is present? >> >> I tried $dbh->selectdb($databasename) but this >>> failed throwing error can't able to locate object method "selectdb" in >>> package dbi::db. >>> >> >> I think the selectdb is part of the Mysql demo mod > > haven't used it in years but here is a quick use of it > > #!/usr/bin/perl > # PERL MODULE > use Mysql; > # MYSQL CONFIG VARIABLES > $host = "localhost"; > $database = "store"; > $tablename = "inventory"; > $user = "username"; > $pw = "password"; > # PERL CONNECT() > $connect = Mysql->connect($host, $database, $user, $pw); > # SELECT DB > $connect->selectdb($database); > > > Mysql I think is a nice wrapper for DBD::mysql but don't quote me on that;) > > cheers > John Scoles > > > There is no such method in DBI, and as far as I know, there was never one. >> >> The only way to specify a database is to use the connect() method of the >> DBI class. >> >> Please help me on this.I work with microsoft sql server >>> 2005. >>> >>> >> What DBD do you use? DBD::ODBC? >> >> Alexander >> >> >> >