mani87 has asked for the wisdom of the Perl Monks concerning the following question:

#!c:\perl64\bin\perl use DBD::Mysql; use DBI; print "Content-type: text/html \n\n"; $host = "localhost"; $database="test555"; $tablename1="t6"; $tablename2 ="table123"; $tablename3="test77"; $user = "root"; $pw = "root"; $connect = DBI->connect($host, $database, $user, $pw); $connect->selectdb($database); $myquery = "INSERT INTO $tablename3 (testcolumn) VALUES ('try')"; $execute = $connect->query($myquery); $affectedrows = $execute->affectedrows($myquery); $lastid = $execute->insertid($myquery); print $affectedrows."<br />"; print $lastid."<br />";
Unable to execute the perl code. **Output message:** *c:\mani\Perl_Scripts>perl mysql_test.pl Content-type: text/html DBI->connect using 'old-style' syntax is deprecated and will be an error in futu re versions at mysql_test.pl line 18 install_driver(root) failed: Can't locate DBD/root.pm in @INC (@INC contains: C: /Perl64/site/lib C:/Perl64/lib .) at (eval 5) line 3. Perhaps the DBD::root perl module hasn't been fully installed, or perhaps the capitalisation of 'root' isn't right. Available drivers: CSV, DBM, ExampleP, File, Gofer, LDAP, Mock, ODBC, Oracle, Pg , Proxy, SQLite, Sponge, Wire10, mysql, mysqlPP. at mysql_test.pl line 18* I have installed DBD- MySQL package and I am not sure of DBI package, whether I installed through ppm. I am attaching a screenshot of all the installed packages related to MySQL. I even searched for MySQL ODBC package, as an alternative, as suggested by a friend. But, couldn't find for **ActivePerl**. I am using ActivePerl in my system. I intially used, command, *use mysql*; *MYSQL->CONNECT($host, $database, $user, $pw);* FOR WHICH I GOT THE MESSAGE INITIALLY, PERL.PM NOT FOUND. i PLACED THE PERL.PM FILE INTO THE PATH AND THEN, I GOT THE MESSAGE, CONNECTION DOESN'T EXIST FOR MYSQL PACKAGE. So, can you please tell the probable area, where I have missed and any related coding issues? Thanks, Mani

Original content restored above by GrandFather. Update follows:

#!C:\perl64\bin\perl.exe -wT use strict; use warnings; use DBI; print "Content-type: text/html \n\n"; # MYSQL CONFIG VARIABLES my $driver = "mysql"; my $database="test555"; my $tablename3="test77"; my $user = "root"; my $pw = "root"; # PERL MYSQL CONNECT() my $dbh = DBI->connect("DBI:$driver:$database", $user, $pw, ) ; my $sth = $dbh->prepare(" SELECT * FROM t6 WHERE paragraph='PQX03904' ") ; $sth->execute() ; #$dbh->disconnect; #exit 0;
When I give $dbh->disconnect, the last before line, system is throwing up error When I comment that, the system is not throwing up any error, neither output. Please help!

Replies are listed 'Best First'.
Re: ActivePerl for MySQL queries in windows7
by moritz (Cardinal) on May 07, 2012 at 17:55 UTC
      I have update the code and the post now...After doing research, I realized, the code initially used was deprecated...Pls. check now once..
        Please do NOT update a node by removing and replacing content.

        If you need to update, do so by surrounding the material to be removed with <strike>...</strike> tags, and marking the inserted, replacement content in such a way that the reader will be able to compare the versions.

        Others will read your node in the future -- tomorrow, next week, next decade. Don't make the replies incomprehensible by deleting the matter to which they addressed themselves.