1,105,295 Community Members

using the "use Mysql" command

Member Avatar
niall_heavey
Light Poster
33 posts since Jan 2009
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Hi all,

I'm sure this is a simple problem, but hopefully someone will be able to help.

I'm trying to connect to mysql through perl, however when I use the command

use Mysql;

it is giving me an error.
I am assuming it is probably something to do with the directories that things are being ran from.
The specific error is as follows:
can't loocate Mysql.pm in @INC (@INC contains: C:/Perl/lib C:/Perl/site/lib)
I am using this in both windows and ubuntu both getting similar errors in both.

If anyone has any ideas please let me know!

Thanks in advance,
N

Member Avatar
mitchems
Posting Whiz in Training
294 posts since Feb 2009
Reputation Points: 12 [?]
Q&As Helped to Solve: 38 [?]
Skill Endorsements: 0 [?]
 
1
 

There is no "use Mysql". You have to connect to MySQL through DBI/DBD:Mysql. Since you're on windows, you will want to include the uwinnipeg ppm server in your ppm manager. It depends on the version of perl you are running. Go to the command prompt and type perl -v. to get the version. Then type ppm and go to the libraries part of ppm and include: cpan.uwinnipeg.ca/PPMPackages/10xx/ (that's for version 5.10). Then search on DBD MySQL and DBI. Install both. Then you can connect like this:

sub goSQL{
use DBI;
my $statement=shift;
print "$statement\n" if($DEBUG);
#my $dbh,
my $user;
my $password;
my $db;
$database="database" if($database eq "");
$user="root";
my $dbh = DBI->connect("dbi:mysql:$database", $user, $password);
if ($dbh){
		my $id;
		my $count;
		my $color;
		my $sth;
		my @rows;
		my $err;
		$sth=$dbh->prepare("$statement");
		$sth->execute();
		my $nf=$sth->{NUM_OF_FIELDS};
		if ($nf!=0){
			while($id=$sth->fetchrow_hashref()){
				push @rows,$id;
			}
		}
		return \@rows;
	} else {
	    return 0;
	}  
}
1;

That will return a reference to an array with hashes of your query results.

$f=goSQL("select * from table");
for (@$f){
  print "$_->{column_name}\n";  
}

Good luck!

Member Avatar
d5e5
Practically a Posting Shark
827 posts since Sep 2009
Reputation Points: 109 [?]
Q&As Helped to Solve: 163 [?]
Skill Endorsements: 2 [?]
 
0
 

I see mitchems has answered your question for installing in Windows. As for ubuntu, I think I installed the DBD::mysql module the lazy way in ubuntu by using the Synaptic Package manager and doing a quick search for libdbd-mysql-perl. You may already have the DBI module installed as it may have been included with your Perl already. You can read more about installing these modules here.

Member Avatar
niall_heavey
Light Poster
33 posts since Jan 2009
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Ok, thank you for your replies. I am not currently at a machine running Ubuntu so I will get back to that if I am having any problems later.

"Go to the command prompt and type perl -v. to get the version. Then type ppm and go to the libraries part of ppm and include: cpan.uwinnipeg.ca/PPMPackages/10xx/ (that's for version 5.10)."

When I am running the ppm (package manager) I can not find the libraries to include the package you are suggesting.

This is perl, v5.10.1 built for MSWin32-x86-multi-thread
(with 2 registered patches, see perl -V for more detail)

Copyright 1987-2009, Larry Wall

Binary build 1007 [291969] provided by ActiveState http://www.ActiveState.com
Built Jan 26 2010 23:15:11

Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.

Complete documentation for Perl, including FAQ lists, should be found on
this system using "man perl" or "perldoc perl".  If you have access to the
Internet, point your browser at http://www.perl.org/, the Perl Home Page.

This is my perl -v information so it is 5.10. If you have any more information about where I could locate this package it would be great.

Thanks again.

N

Member Avatar
mitchems
Posting Whiz in Training
294 posts since Feb 2009
Reputation Points: 12 [?]
Q&As Helped to Solve: 38 [?]
Skill Endorsements: 0 [?]
 
0
 

Go to the command line and type "ppm". You might have to go to c:\perl\bin to get it to work if it's not in your path. Then go to the menu under "Properties" and go to repositories. Include the cpan.uwinnipeg.ca/PPMPackages/10xx/ in the ppm manager. Search on DBD Mysql and on DBI. Install both and it should work. If you don't have ppm, I can explain how to install it from the shell or manually.

Member Avatar
Jaycy
Newbie Poster
1 post since Feb 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Hi all,
I had the same problem and i tried the similar way to solve the problem. But am using perl version 5.14.2. How can i install the PPM. Can anyone help me please...?

Member Avatar
d5e5
Practically a Posting Shark
827 posts since Sep 2009
Reputation Points: 109 [?]
Q&As Helped to Solve: 163 [?]
Skill Endorsements: 2 [?]
 
0
 

I don't have Windows on my computer so I can't answer your question if you are asking about installing PPM under Windows. You have a better chance of getting the attention of someone who can help you if you start a new thread with a relevant title such as "Installing PPM (Perl Package Manager) under Windows." (This thread title is "using the 'use Mysql' command" and it's more than a year old.)

If you have a non-Windows platform such as Mac-OS or Ubuntu, please include that information in your question.

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: