CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Problem with connecting with Mysql Server on Windows 7

 



zak100
User

Oct 13, 2013, 8:25 AM

Post #1 of 3 (761 views)
Problem with connecting with Mysql Server on Windows 7 Can't Post

Hi,
I have got a program from for connecting with datbase. But its giving me problems. I am using Mysql Server:

Code
Your MySQL connection id is 1 
Server version: 5.1.68-community MySQL Community Server (GPL)

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> use TestDB;
Database changed
mysql> showtables;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'showt
ables' at line 1
mysql> show tables;
+------------------+
| Tables_in_testdb |
+------------------+
| contacts |
+------------------+
1 row in set (0.06 sec)

I am using Active Perl. My perl code is :

Code
#!C:/Perl64/bin/perl.exe 
use DBI;
##Create table using cgi
$dbh = DBI->connect("dbi:mysql:TestDB", 'root','zulfi12345') or die "Unable to connect: $DBI::errstr\n";
##$sql = "CREATE TABLE contacts (
## id INT NOT NULL AUTO_INCREMENT,
## PRIMARY KEY(id),
## first_name VARCHAR(64),
## surname VARCHAR(64),
## email VARCHAR(255))";
##$sth = $dbh->prepare($sql);
##$sth->execute() or die "SQL Error: $DBI::errstr\n";

##insert data
$sth = $dbh->prepare("INSERT INTO contacts(first_name, surname, email) VALUES(?,?,?)");
$sth->execute("Nick", "Jones", "nick.jones\@foo.com");
$sth->execute("Matt", "Smith", "matt.smith\@bar.com");
$sth->execute("Matt", "Brown", "matt.brown\@baz.com");

## query the database
$sth = $dbh->prepare("SELECT first_name, surname, email FROM contacts WHERE first_name = ?");
$sth->execute("Matt");

## Display the contents

print "Content-type: text/html\n\n";
print <<HTML_PAGE;
<html>
<head>
<title>Database Test</title>
</head>
<body>
<h1>Database Test</h1>
<table>
<tr>
<th>First Name</th>
<th>Surname</th>
<th>Email</th>
</tr>
</table>
</body>

HTML_PAGE
exit;


I am getting following error:


Quote
D:\Zulfi\PERL MAIN FOLDER>perl CTdb.pl
install_driver(mysql) failed: Can't locate DBD/mysql.pm in @INC (@INC contains:
C:/Perl64/site/lib C:/Perl64/lib .) at (eval 3) line 3.
Perhaps the DBD::mysql perl module hasn't been fully installed,
or perhaps the capitalisation of 'mysql' isn't right.
Available drivers: CSV, DBM, ExampleP, File, Gofer, ODBC, Oracle, Pg, Proxy, SQL
ite, Sponge.
at CTdb.pl line 4.

D:\Zulfi\PERL MAIN FOLDER>


Somebody plz guide me how to solve this problem.

Zulfi.


FishMonger
Veteran / Moderator

Oct 13, 2013, 9:43 AM

Post #2 of 3 (757 views)
Re: [zak100] Problem with connecting with Mysql Server on Windows 7 [In reply to] Can't Post

You need to install the DBD::mysql module. ActivePerl comes with the ppm utility to install modules.

i.e., from the command line run this command:

Quote
ppm install DBD::mysql



zak100
User

Oct 13, 2013, 11:42 AM

Post #3 of 3 (752 views)
Re: [FishMonger] Problem with connecting with Mysql Server on Windows 7 [In reply to] Can't Post

Hi,
Thanks it worked.

Code
C:\Users\HP>ppm install DBD::mysql 
Downloading DBD-mysql-4.022...done
Unpacking DBD-mysql-4.022...done
Generating HTML for DBD-mysql-4.022...done
Updating files in site area...done
12 files installed

Zulfi.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives