Here's a test script that I use to check out a new
database whenever I create a new one:

#!/usr/bin/perl
use DBI;
$database  = "oncall";
$user      = "oncall";
$code      = "1donca";

print "INFO:  Connecting to database: $database\n";
$connection = DBI->connect("DBI:mysql:$database",
$user, $code) || die "Cannot connect to $database";
print "INFO:  Connection established\n\n";
$statement = "select * from members where member_id =
3";
$cursor = $connection->prepare($statement) or die
"Can't prepare $statement: $connection->errstr\n";
$cursor->execute;
print "INFO:  Printing Results:\n\n";
while(@row = $cursor->fetchrow_array)
        {
        foreach $field (@row)
                {
                print "field = $field ";
                }
        print "\n";
        }
$rc = $cursor->finish;
$rc = $connection->disconnect;
exit;

Hope this helps!

-Stephen Spalding

--- Starman P <[EMAIL PROTECTED]> wrote:
> All
> i wrote the following perl script and tried to
> connect to mysql database:
> # File name fig13.pl
> #!/usr/bin/perl -w
> 
> use DBI;
> 
> $dbh =
>
DBI->connect("DBI:mysql:zipcodes","username","mypass");
> if ($dbh) {
> print "Connection successful\n";
> }
> 
> then after giving execute permission, i tried to run
> it by:
> # perl fig13.pl
> 
> I get error message:
> DBI->connect(zipcodes) failed: Can't connect to
> local MySQL server through 
> socket '/var/lib/mysql/mysql.sock' (2) at ./fig13.pl
> line 5
> 
> zipcodes is the database i created in mysql.
> When i manually type
> # mysql -u username -p zipcodes
> I get prompt for passwd and when i tyep it, it takes
> me to the mysql promt.
> So mysql server is running and that user has
> permission to acces "zipcodes" 
> database.
> What did i wrong or what can i do to make it work??
> 
> thanks for your help
> 
> Pran
> 
>
_________________________________________________________________
> MSN Photos is the easiest way to share and print
> your photos: 
> http://photos.msn.com/support/worldwide.aspx
> 
> 
> 
> _______________________________________________
> Redhat-list mailing list
> [EMAIL PROTECTED]
>
https://listman.redhat.com/mailman/listinfo/redhat-list


__________________________________________________
Do You Yahoo!?
Yahoo! Autos - Get free new car price quotes
http://autos.yahoo.com



_______________________________________________
Redhat-list mailing list
[EMAIL PROTECTED]
https://listman.redhat.com/mailman/listinfo/redhat-list

Reply via email to