Re: MSQL though a shell

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



#!/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@xxxxxxxxx>
Para: For users of Fedora <fedora-list@xxxxxxxxxx>
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/
-- 
fedora-list mailing list
fedora-list@xxxxxxxxxx
To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list
Guidelines: http://fedoraproject.org/wiki/Communicate/MailingListGuidelines

[Index of Archives]     [Current Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]     [Fedora Docs]

  Powered by Linux