MSQL though a shell

Dennis Kaptain dkaptain at yahoo.com.mx
Tue Oct 14 01:47:35 UTC 2008


#!/usr/bin/perl -w
# this PERL script will connect to a remote MySQL database and execute a select statement

use DBI; # DBI is available at CPAN.org if you don't have it installed in PERL

# DBI Variables
my $dbh;  # database handle
my $sth;  # statement handle
my $sta;  # a statement
my @rows; # returned data
my $dbHost = "databaseHost"; # put your database host name here
my $dbName = "yourDatabaseName"; # put your database name here
my $dbUser = "DatabaseUserName"; # put your username here
my $dbPasswd = "databasePwd"; # put your database password here

# connect to the database
$dbh = DBI->connect("dbi:mysql:".$dbName.":".$dbHost, $dbUser, $dbPwd)
               or die "Can't connect to database: $DBI::errstr\n\n";
$sta = "SELECT col1,col2 from table where item=\"1\" order by key";
$sth = $dbh->prepare($sta) or die "Can't prepare statment: $DBI::errstr\n\n";
$sth->execute or die "Can't execute statment: $DBI::errstr\n\n";
while (@rows = $sth->fetchrow_array() ) {
   print $rows[0];
   print $rows[1];
}





________________________________
De: Franck Y <franck110 at gmail.com>
Para: For users of Fedora <fedora-list at redhat.com>
Enviado: lunes, 13 de octubre, 2008 16:10:06
Asunto: MSQL though a shell


Hello guys, 

I have to query a remote database that run under MSQL and get the result within a shell/perl script ?

Does anyone of you did that ? I would not like to purchase a ODBC driver since it is for a project at school 

Thanks

Franck



      ¡Todo sobre Amor y Sexo!
La guía completa para tu vida en Mujer de Hoy.                       
http://mx.mujer.yahoo.com/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listman.redhat.com/archives/fedora-list/attachments/20081013/9a59bd3e/attachment-0001.htm>


More information about the fedora-list mailing list