MDTech.us_MAN has asked for the wisdom of the Perl Monks concerning the following question:
Here is what I already have:my @results; while (@results = $query1->fetchrow_array()) { foreach(@results) { if ($index = "1") { print "\nName: $_\n"; $index = "2" } else { if ($index = "2") { print "\nEmail: $_\n"; $index = "2" } } } }
Maxwell D.#!/usr/bin/perl use strict; use DBI; #my $username = 'root'; #my $dsn = 'DBI:mysql:mysql'; my $conn = DBI->connect('DBI:mysql:<DBName>;host=<ServerIP>', '<Userna +me>', '<Password>', { RaiseError => 1 }) || die "Could not connect to + the database"; my $console = $ARGV[0]; my $query = "SELECT * FROM People where Name = '$console'"; my $query1 = $conn->prepare($query) || die "Error preparing query" . $ +conn->errstr; $query1->execute || die "Error executing query" . $query1->errstr; print "$query"; my $index = "1"; my @results; while (@results = $query1->fetchrow_array()) { foreach(@results) { if ($index = "1") { print "\nName: $_\n"; $index = "2" } else { if ($index = "2") { print "\nEmail: $_\n"; $index = "2" } } } } if ($query1->rows == 0 ) { print "No Records", "\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Need help writing a script that interacts with a MySQL DB!
by chromatic (Archbishop) on Sep 30, 2012 at 03:33 UTC | |
by Anonymous Monk on Sep 30, 2012 at 09:49 UTC | |
|
Re: Need help writing a script that interacts with a MySQL DB!
by tinita (Parson) on Sep 30, 2012 at 10:54 UTC | |
|
Re: Need help writing a script that interacts with a MySQL DB!
by ckj (Chaplain) on Sep 30, 2012 at 05:43 UTC | |
by CountZero (Bishop) on Sep 30, 2012 at 07:36 UTC | |
|
Re: Need help writing a script that interacts with a MySQL DB!
by Anonymous Monk on Sep 30, 2012 at 06:16 UTC |