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

Re: [MacPerl] MacPerl and MySQL



At 15.41 -0400 2000.06.06, Patrick Larkin wrote:
>Is there some way I can use MacPerl and the Perl DBI to access records in a
>MySQL database and have results displayed on my MacOS webserver?

Yes.  I can think of two ways right now.

1.  Use DBD::Proxy and DBI::ProxyServer.  Instructions are on 
http://pudge.net/macperl/.

2.  Use Apple events (like Mac::Glue or something) to talk to MacSQL Monitor, 
which is not as easy to do and a little less reliable right now.  MacSQL Monitor 
is in beta and sometimes I have found it to be a bit flaky with Apple events.  
However, since the current databases I am using most are behind a firewall, I am 
not using MacSQL Monitor much, so I don't recall all the issues involved.

    http://www.lilback.com/macsql/

For fun, a script using MacSQL Monitor is below.  It gets the most recent comments from a Slash database, and prints out URLs to them, so I can go look at the most recent comments.

#!perl -w
use Mac::Glue ':all';
use strict;
use vars '@a';

my $host = MacPerl::Ask 'Host?' or die;
my $user = MacPerl::Ask 'User?' or die;
my $pass = MacPerl::Ask 'Pass?' or die;

my $sql = new Mac::Glue 'MacSQL';
my $db = $sql->make(new => 'session', with_properties => {
	host		=> $host,
	user_name	=> $user,
	password	=> $pass,
	type		=> enum('MySQL')
});
die $^E if $^E;

$sql->set( $sql->prop(current_database => $db), to => $sql->obj(database => $user => $db));
die $^E if $^E;

$sql->query($db,
    sending => 'SELECT sid, cid, uid, date FROM comments ORDER BY date DESC LIMIT 30'
);
die $^E if $^E;

my $rs = $sql->get($sql->obj(result_set => gLast, $db));
for (1 .. 30) {
	@a = $sql->get( $sql->prop(value => row => $_, $rs));
	die $^E if $^E;
	push @a, "http://$host/article.pl?sid=$a[0]#$a[1]";
	write;
}

print <<EOT;  # footer
+-------------------+--------+-------+---------------------+-----------------------------------------------------------------+
EOT

format STDOUT_TOP =
+-------------------+--------+-------+---------------------+-----------------------------------------------------------------+
| sid               | cid    | uid   | date                | url                                                             |
+-------------------+--------+-------+---------------------+-----------------------------------------------------------------+
.

format STDOUT =
| @<<<<<<<<<<<<<<<< | @<<<<< | @<<<< | @<<<<<<<<<<<<<<<<<< | @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< |
@a
.

__END__

-- 
Chris Nandor       |     pudge@pobox.com      |     http://pudge.net/
Andover.Net        | chris.nandor@andover.net | http://slashcode.com/

# ===== Want to unsubscribe from this list?
# ===== Send mail with body "unsubscribe" to macperl-request@macperl.org