Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

perl-dbi-mysql code location

Status
Not open for further replies.

PROFESSORSPARKIE

Instructor
Oct 24, 2002
181
US
I write perl programs, no problem. I install MySQL and do all kinds of things at the command line & through standard input script files.

I have downloaded DBI library code but when I try to run a perl program with a database the execution time error is because the DBI code can't be found.
My database code seems to be OK, no errors there.

Facts:
WIN/XP Serv-2
Latest perl in a c:\perl\bin
latest stable Mysql in c:\mysql\bin
trying to run perl program in \my-web-page\cgi-bin
in my local & web host site.
Questions:
where di need to have the DBI code & what must be in my PATH
I just seem to be missing something about DBI file location

Any suggestions?

I teach a lot of programming so I can learn. You can never learn it all.
 
do you have the mysql drivers installed also? Does the http server work with other cgi scripts? Have you checked the server error logs?

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
I run all kinds of server based cgi-bin folder perl-cgi programs using server based files with locking etc.I create, load & delete sequential & hash-index files, no problem

I use "use CGI::Carp qw(fatalsToBrowser);" error feedback but I am getting perl expansion error before an attempt to reach mysql. I am also trying most local install with Win-XP because it is faster.

I followed the steps outlined in two different perl-mysql texts which does an install of DBI & driver I thought.

my question is where is the driver & dbi supost to be located.

After starting my local database server I try a simple batch request with:

my browser loads a local web page from:
c:\my-web-page\which uses a form action to run
c:\my-web-page\cgi-bin\progname.pl
which starts the open connect.

I do these kinds of activities all the time on
local and web server based other program & files
with no problems

I was just taking a 'read sequential file' and trying
a database.

I use local sql> command entry with no problem.
I am just missing something.

Thanks in advance for any assistance.

I teach a lot of programming so I can learn. You can never learn it all.
 
it's supposed to be loaded under the perl directory. I'm not sure what you are getting at. You said you are on windows right? Are you running activestate's perl? Have you tried just writing a simple 5 line DB script and getting it DBI/DBD working from a simple script before you complicate things by adding in the web based parts? You don't even need to run a query but you need to make sure you can connect to your local server via the dbi/dbd modules.

 
yes, I am using Activestate binary download & I was trying to do as simple a request as possible. I used the following sample education code as a model for my code. at interpret time I get a message about DBI linkage.

Since this was my first time trying to intergrate database & cgi in perl, I thought it was just a dumb simple thing I did like not putting something in the right directory. I have been programming for 44 years in 10 different languages and know how easy "I" can let something slip bye. I will backup my thought process and charge with a fresh attempt.

Here is the sample code.

#!/usr/bin/perl

use CGI;
use CGI ':standard';
use CGI::Carp qw(fatalsToBrowser);
use DBI;

$database = "database name";
$hostname = "database hostname";
$username = "database username";
$password = "database password";

$db = DBI->connect("DBI:mysql:$database:$hostname", $username, $password);

$query = $db->prepare("SELECT * FROM test");
$query->execute;

$numrows = $query->rows;

while (@array = $query->fetchrow_array) {
($field1, $field2, $field3) = @array;
print "field1 = $field1, field2 = $field2, field3 = $field3 n";
}

$query->finish;
$db->disconnect;

exit(0);


I teach a lot of programming so I can learn. You can never learn it all.
 
What does this mean:

but I am getting perl expansion error

are you getting an error message? What is it?

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
When you did the dbi:mysql install did you do it via ppm?

What error do you get for the above code because at first glance.. it looks fine.

You can get rid of everything between the connect and disconnect statements for your testing. It would seperate dbi problems from query/db issues.


Travis
 
TO: KevinADC - I mean, as the perl interpreter tries to go to the DBI on the USE statement at the start of execution.
He says he can't find the DBI.

TO: travis69 - I used PPM to install at least once at the beginning I have tried a number of things and have gotten confused as to what happened when. Then I tried copy of the module to different directories.

Maybe I should just clean out everything and restart from scratch and get screen captures as documentation then if it does not work to revisit with you all.

I assume it doesn't matter in which order I install perl-mysql-DBI-drivers. I would think the installation should just be a FTP to a specific folder,

Thanks again, I was looking for a quicky answer thinking I had missed an obvious step.

I teach a lot of programming so I can learn. You can never learn it all.
 
If you are using the activestate then I would suggest using the PPM for all of your modules. It works well and has everything you will need. I would redo your perl install. You shouldn't have to manually install anything.

 
TO: TRAVS69

Thanks, I will try it ASAP but I am at the end of quarters and have to create-administer-&-grade exams. It will be a few weeks before I get back to the problem. Programming is more fun then exams but teaching & exams pay the bills.

Thanks again.

I teach a lot of programming so I can learn. You can never learn it all.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top