Listing of db/select.pl


#!/usr/bin/perl
#
# Make a SQL SELECT from MySQL database
#
# Tested with WinXP and perl, v5.8.0 built for MSWin32-x86-multi-thread
# Binary build 806 provided by ActiveState Corp. http://www.ActiveState.com
# Built 00:45:44 Mar 31 2003
#
# ------------------------------
# Installing MySQL API into perl:
# (The interface requires Perl Version 5.6.0 or later)
# ppm> install DBI
# ppm> install DBD-MySQL
# ------------------------------
# Change History:
# 2004-11-22 jje - SQL script created for MySQL 4.0
# 2005-03-30 jje - Adapted for MySQL 4.1.1 and above (renamed columns UTC_TIME and UTC_DATE into UTCTIME and UTCDATE)

require 5.008;
use strict;
use DBI;

  my $data_source = "dbi:mysql:gsmtrack";
  my $user = "root";
  my $password = shift || ""; # you may give password at the command line
  my $dbh = DBI->connect($data_source, $user, $password)
      or die "Can't connect to $data_source: $DBI::errstr";

# If you get the following error with MySQL 4.1.1 or newer
# 
#   DBI connect('gsmtrack','root',...) failed: Client does not support authenticatio
#   n protocol requested by server; consider upgrading MySQL client ...
#
# Reset the root password to pre-4.1 style as follows: 
#   mysql>  SET PASSWORD = OLD_PASSWORD('newpwd');
#
# (See http://dev.mysql.com/doc/mysql/en/old-client.html)

  my $sth = $dbh->prepare( q{
            SELECT * 
            FROM GPS
  }) or die "Can't prepare statement: $DBI::errstr";
  my $rc = $sth->execute
      or die "Can't execute statement: $DBI::errstr";
  print "Query will return $sth->{NUM_OF_FIELDS} fields.\n\n";
  print "Field names: @{ $sth->{NAME} }\n\n";

  my $row;
  while ($row = $sth->fetchrow_arrayref) {
    print "@$row\n";
  }
  # check for problems which may have terminated the fetch early
  die $sth->errstr if $sth->err;
  $dbh->disconnect;

exit;

This file was generated by Gabriel Knoy's perl2html script.