Read through the man doc lcalero gave you it tells everything you need to
know.  Below is a basic example to help get you started:


#!/usr/bin/perl


use CGI;


use DBI;
        $hostname = 'www.hostname.com';
        $database = 'nameofdatabase';
        $user     = 'username';
        $password = 'password';
        $driver   = 'mysql';
        $dsn      = "DBI:$driver:database=$database;host=$hostname";


my $dbh = DBI->connect($dsn, $user, $password)  or die "Cant connect to
the DB:
$DBI::errstr\n";

my $sth = $dbh->prepare("SELECT attributes from entities");

$sth->execute();

my $something;
while (my @row = $sth->fetchrow_array()) {
 $something .= qq|  $row[2]$row[1]etc.\n|;

}

#each row is respective to the row returned from the query with the first
being row 0

$sth->finish;






-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, February 12, 2002 4:11 AM
To: Andy Cheng
Cc: [EMAIL PROTECTED]
Subject: Re: How to access MySql using Perl. Help



> I am new to MySql. I have MySql installed in my Linux PC.  How do I
connect
> to MySql using Perl script and assign the result of a query to an array?
> Where could I find a sample code?  Thank you.

  man DBD::mysql

  Cheers.

--
  Luis Calero Muņoz
  $email{luis} = '[EMAIL PROTECTED]'
  $who{luis} = 'sysadm at ociojoven dot com'



---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail
<[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php


---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to