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]     [Older Fedora Users]     [Fedora Announce]     [Fedora Package Announce]     [EPEL Announce]     [Fedora Magazine]     [Fedora News]     [Fedora Summer Coding]     [Fedora Laptop]     [Fedora Cloud]     [Fedora Advisory Board]     [Fedora Education]     [Fedora Security]     [Fedora Scitech]     [Fedora Robotics]     [Fedora Maintainers]     [Fedora Infrastructure]     [Fedora Websites]     [Anaconda Devel]     [Fedora Devel Java]     [Fedora Legacy]     [Fedora Desktop]     [Fedora Fonts]     [ATA RAID]     [Fedora Marketing]     [Fedora Management Tools]     [Fedora Mentors]     [SSH]     [Fedora Package Review]     [Fedora R Devel]     [Fedora PHP Devel]     [Kickstart]     [Fedora Music]     [Fedora Packaging]     [Centos]     [Fedora SELinux]     [Fedora Legal]     [Fedora Kernel]     [Fedora OCaml]     [Coolkey]     [Virtualization Tools]     [ET Management Tools]     [Yum Users]     [Tux]     [Yosemite News]     [Gnome Users]     [KDE Users]     [Fedora Art]     [Fedora Docs]     [Asterisk PBX]     [Fedora Sparc]     [Fedora Universal Network Connector]     [Libvirt Users]     [Fedora ARM]

  Powered by Linux