Re: DBI Connect Failure
Rudy, Thanks for your mail. I have Postgres version 7.1, I can connect to my database with psql and make changes, and my operating system is Sun Solaris 5.7. After you and Jeff wrote, I - reinstalled DBI-1.13 with the environment variables for DBI_DSN, DBI_USER and DBI_PASS - downloaded and installed DBD-Pg-1.00, with environment variables for POSTGRES_LIB and POSTGRES_INCLUDE - accessed perldoc with my postgres account - got my first script to post an sql statement to my web page (but that's all) - checked my fetch row subroutine (couldn't find an error), and then my second script, which instead of printing an acronym and its meaning based on form input, simply prints out the whole acronym table. Now I got this error: Can't locate object method execute via package DBI::db (perhaps you forgot to load DBI:db? Database handle destroyed without explicit disconnect. I think that it can't find DBI:db because I have incorrect setenv DBI_DSN parameters. The DBI module instructions say that it should point to my database drivers, and that ODBC should be in there, but I have no ODBC modules installed, and the only odbc folder I could find was in the source directory of my postgres installation files. Anyway, DBI_DSN now has dbdi:ODBC:POSTGRES. Let me know if that's correct or if I should look elsewhere, thanks! Christine Rudy Lippan wrote: I'm studying the DBI module to get smarter on this. I was not able to complete installation on the Pg module (I have pg95perl5-1.2.0), because I couldn't find Pg.pm modules in the right places. Tried to reinstall, but it failed on make because libpq.so.1 is missing from usr/local/pgsql/lib. Tried checking www.cpan.org today to make sure that I have the correct Pg module, but it was down. You can get the latest version of DBD::Pg from 'http://dbi.symbolstone.org/index.html' which is probably what you want. I don't think that you want be be using pg95perl5/Pg.pm. When you get DBD::Pg it will make you set POSTGRES_INCLUDE, and POSTGRES_LIB which tell DBD:Pg where to find libpq.so and other things that are required to build DBD::Pg. By the by what version of postgres are you using? Can you connect to it with psql? What operating system/version are you using? I got no errors on the PgSQL.pm install, so it would be easier for me to use that, presuming I can get DBD running correctly. I don't know about that... Tried using perl documentation, but got only the usage index. I can't run perldoc, because I get a warning: Superuser must not run ~/perldoc without security audit and taint checks. perldoc will not let you run it as root. Create another user and then run perldoc as that user || you can try su -c nobody 'perldoc DBI' and see if that works. I have a colleague who's betting this is a total waste of time, given the ignorance I've just demonstrated. But as long as I do the other stuff I'm supposed to be doing, trying this out still beats learning MS Access. It is not a waste of time, for we all have to start somewhere. And as long as you learn something, I would consider it a worthwhile exercise. Later, Rudy
RE: DBI Connect Failure
-Original Message- From: Christine Kluka [mailto:[EMAIL PROTECTED]] Sent: Saturday, June 23, 2001 1:29 AM To: Rudy Lippan Cc: Ronald J Kimball; Chase Michael A.; Neil Lunn; [EMAIL PROTECTED] Subject: Re: DBI Connect Failure Rudy, I'm studying the DBI module to get smarter on this. I was not able to complete installation on the Pg module (I have pg95perl5-1.2.0), because ^^ Don't know exactly what this is but it sure isn't anything to do with DBI I couldn't find Pg.pm modules in the right places. Tried to reinstall, but it failed on make because libpq.so.1 is missing from usr/local/pgsql/lib. Tried checking www.cpan.org today to make That's the Postrgress client interface module. Not part of Perl. Check your Postgress installation, but the chances are that this file is actually located elsewhere in your system than /usr/local. As for CPAN, this is mirrored all around the world. You really should be using the cpan shell with your nearest mirror. See the comments on perldoc later. sure that I have the correct Pg module, but it was down. So naturally the database connection for DBI/DBD::Pg failed, but at least this time I connected to DBI.pm, w/ response can't locate DBD/Pg.pm in @INC. I have DBD installed, but I didn't set the environment variables for DBI_DSN, DBI_USER, DBI_PASS and ODBCHOME when I installed it, and I only know 2 out of the 4 anyway. Again, more studying. That doesn't sound like DBD::Pg to me but more like DBD::ODBC. I got no errors on the PgSQL.pm install, so it would be easier for me to use that, presuming I can get DBD running correctly. Tried using perl documentation, but got only the usage index. I can't run perldoc, because I get a warning: Superuser must not run ~/perldoc without security audit and taint checks. You really should have your own account that is not root (or uid 0).Running your shell as the superuser all day may not be a very safe idea. Perhaps you should review your security settings and possibly use a utility such as sudo. I have a colleague who's betting this is a total waste of time, given the ignorance I've just demonstrated. But as long as I do the other stuff I'm supposed to be doing, trying this out still beats learning MS Access. Thanks all of you for the tips! Christine Rudy Lippan wrote: Christine, However I still can't connect to my sample Postgres database. From the code you posted, it does not look like you are using DBI, but rather PgSQL. You would probably be far better off using DBI, for PgSQL is considered 'alpha quality' || at least that is what the README on CPAN says. If you have DBI/DBD::Pg installed, try this: use DBI; my $dbh = DBI-connect('DBI:Pg:dbname=mydb','','') || die $DBI::errstr; Later, Rudy __ Please Note : Only the intended recipient is authorised to access or use this e-mail. If you are not the intended recipient, please delete this e-mail and notify the sender immediately. The contents of this e-mail are the writer's opinion and are not necessarily endorsed by the Gunz Companies unless expressly stated. We use virus scanning software but exclude all liability for viruses or similar in any attachment.
Re: DBI Connect Failure
Rudy, I'm studying the DBI module to get smarter on this. I was not able to complete installation on the Pg module (I have pg95perl5-1.2.0), because I couldn't find Pg.pm modules in the right places. Tried to reinstall, but it failed on make because libpq.so.1 is missing from usr/local/pgsql/lib. Tried checking www.cpan.org today to make sure that I have the correct Pg module, but it was down. So naturally the database connection for DBI/DBD::Pg failed, but at least this time I connected to DBI.pm, w/ response can't locate DBD/Pg.pm in @INC. I have DBD installed, but I didn't set the environment variables for DBI_DSN, DBI_USER, DBI_PASS and ODBCHOME when I installed it, and I only know 2 out of the 4 anyway. Again, more studying. I got no errors on the PgSQL.pm install, so it would be easier for me to use that, presuming I can get DBD running correctly. Tried using perl documentation, but got only the usage index. I can't run perldoc, because I get a warning: Superuser must not run ~/perldoc without security audit and taint checks. I have a colleague who's betting this is a total waste of time, given the ignorance I've just demonstrated. But as long as I do the other stuff I'm supposed to be doing, trying this out still beats learning MS Access. Thanks all of you for the tips! Christine Rudy Lippan wrote: Christine, However I still can't connect to my sample Postgres database. From the code you posted, it does not look like you are using DBI, but rather PgSQL. You would probably be far better off using DBI, for PgSQL is considered 'alpha quality' || at least that is what the README on CPAN says. If you have DBI/DBD::Pg installed, try this: use DBI; my $dbh = DBI-connect('DBI:Pg:dbname=mydb','','') || die $DBI::errstr; Later, Rudy
Re: DBI Connect Failure
I'm studying the DBI module to get smarter on this. I was not able to complete installation on the Pg module (I have pg95perl5-1.2.0), because I couldn't find Pg.pm modules in the right places. Tried to reinstall, but it failed on make because libpq.so.1 is missing from usr/local/pgsql/lib. Tried checking www.cpan.org today to make sure that I have the correct Pg module, but it was down. You can get the latest version of DBD::Pg from 'http://dbi.symbolstone.org/index.html' which is probably what you want. I don't think that you want be be using pg95perl5/Pg.pm. When you get DBD::Pg it will make you set POSTGRES_INCLUDE, and POSTGRES_LIB which tell DBD:Pg where to find libpq.so and other things that are required to build DBD::Pg. By the by what version of postgres are you using? Can you connect to it with psql? What operating system/version are you using? I got no errors on the PgSQL.pm install, so it would be easier for me to use that, presuming I can get DBD running correctly. I don't know about that... Tried using perl documentation, but got only the usage index. I can't run perldoc, because I get a warning: Superuser must not run ~/perldoc without security audit and taint checks. perldoc will not let you run it as root. Create another user and then run perldoc as that user || you can try su -c nobody 'perldoc DBI' and see if that works. I have a colleague who's betting this is a total waste of time, given the ignorance I've just demonstrated. But as long as I do the other stuff I'm supposed to be doing, trying this out still beats learning MS Access. It is not a waste of time, for we all have to start somewhere. And as long as you learn something, I would consider it a worthwhile exercise. Later, Rudy
Re: DBI Connect Failure
Ron, Michael, Thanks, using option 1, all the syntax errors are cleared up! I'm not too clear on where the print statements are needed, so if you could refer me to some documentation about this, I'd appreciate it. However I still can't connect to my sample Postgres database. On: package PgSQL; use strict; use PgSQL::Cursor; use CGI qw(:standard); my $dbh; $dbh = db_connect(mydb) or die Error: $PgSQL::error; print $dbh; I get: Undefined subroutine PgSQL::db_connect called Thanks again for your help, Christine Ronald J Kimball wrote: On Wed, Jun 20, 2001 at 03:47:31PM +0200, Christine Kluka wrote: Neil, Thanks, I added my to this variable and to the array and hash declarations in my row subroutine -- this eliminated the not imported errors. Now when I execute the script I am prompted for explicit package names for each instance of a scalar, array or hash. I believe that if I declare the fully qualified package name where the database handler is invoked, this should take care of the problem. I've tried several ways of doing this, but they all fail on syntax or for more serious reasons. That's another error that means you haven't declared your variables. When you use strict 'vars', you have three options for each variable. Declare it with my: my $lexical_variable; $lexical_variable = 7; print $lexical_variable; Declare it with use vars: use vars qw/ $global_variable /; $global_variable = 7; print $global_variable; Specify the package name every time you use it: $main::global_variable = 7; print $main::global_variable; Most people prefer the first two options. Ronald
RE: DBI Connect Failure
Well do you have a db_connect subroutine defined for the PgSQL namespace? It's telling you the exact problem. Ilya -Original Message- From: Christine Kluka To: Ronald J Kimball; Chase Michael A. Cc: Neil Lunn; [EMAIL PROTECTED] Sent: 6/21/01 6:14 AM Subject: Re: DBI Connect Failure Ron, Michael, Thanks, using option 1, all the syntax errors are cleared up! I'm not too clear on where the print statements are needed, so if you could refer me to some documentation about this, I'd appreciate it. However I still can't connect to my sample Postgres database. On: package PgSQL; use strict; use PgSQL::Cursor; use CGI qw(:standard); my $dbh; $dbh = db_connect(mydb) or die Error: $PgSQL::error; print $dbh; I get: Undefined subroutine PgSQL::db_connect called Thanks again for your help, Christine Ronald J Kimball wrote: On Wed, Jun 20, 2001 at 03:47:31PM +0200, Christine Kluka wrote: Neil, Thanks, I added my to this variable and to the array and hash declarations in my row subroutine -- this eliminated the not imported errors. Now when I execute the script I am prompted for explicit package names for each instance of a scalar, array or hash. I believe that if I declare the fully qualified package name where the database handler is invoked, this should take care of the problem. I've tried several ways of doing this, but they all fail on syntax or for more serious reasons. That's another error that means you haven't declared your variables. When you use strict 'vars', you have three options for each variable. Declare it with my: my $lexical_variable; $lexical_variable = 7; print $lexical_variable; Declare it with use vars: use vars qw/ $global_variable /; $global_variable = 7; print $global_variable; Specify the package name every time you use it: $main::global_variable = 7; print $main::global_variable; Most people prefer the first two options. Ronald
Re: DBI Connect Failure
You should be assigning DBI-connect() to $dbh. I'm not sure what all arguments you need for DBD::Postgresql (run perldoc DBD::Postgress to see), but you should at least include error checking of some sort (run perldoc DBI for examples). -- Mac :}) ** I normally forward private database questions to the DBI mail lists. ** Give a hobbit a fish and he'll eat fish for a day. Give a hobbit a ring and he'll eat fish for an age. - Original Message - From: Christine Kluka [EMAIL PROTECTED] To: Ronald J Kimball [EMAIL PROTECTED]; Chase Michael A. [EMAIL PROTECTED] Cc: Neil Lunn [EMAIL PROTECTED]; [EMAIL PROTECTED] Sent: Thursday, June 21, 2001 05:14 Subject: Re: DBI Connect Failure Ron, Michael, Thanks, using option 1, all the syntax errors are cleared up! I'm not too clear on where the print statements are needed, so if you could refer me to some documentation about this, I'd appreciate it. However I still can't connect to my sample Postgres database. On: package PgSQL; use strict; use PgSQL::Cursor; use CGI qw(:standard); my $dbh; $dbh = db_connect(mydb) or die Error: $PgSQL::error; print $dbh; I get: Undefined subroutine PgSQL::db_connect called Thanks again for your help, Christine Ronald J Kimball wrote: On Wed, Jun 20, 2001 at 03:47:31PM +0200, Christine Kluka wrote: Neil, Thanks, I added my to this variable and to the array and hash declarations in my row subroutine -- this eliminated the not imported errors. Now when I execute the script I am prompted for explicit package names for each instance of a scalar, array or hash. I believe that if I declare the fully qualified package name where the database handler is invoked, this should take care of the problem. I've tried several ways of doing this, but they all fail on syntax or for more serious reasons. That's another error that means you haven't declared your variables. When you use strict 'vars', you have three options for each variable. Declare it with my: my $lexical_variable; $lexical_variable = 7; print $lexical_variable; Declare it with use vars: use vars qw/ $global_variable /; $global_variable = 7; print $global_variable; Specify the package name every time you use it: $main::global_variable = 7; print $main::global_variable; Most people prefer the first two options. Ronald
Re: DBI Connect Failure
Ronald, Thanks for your reply. I: - declared $i=0; -- it still fails to import I've tried various other things, like - declaring $i as STDIN, then chomping it -- same result - using code from http://www.perl.com/pub/1999/10/DBI.html#About_Relational_Databases_Gener for DBI-connect, but also using the code that I have -- got method not supported Ill keep trying. In the meantime, any ideas are appreciated, thanks! Christine Ronald J Kimball wrote: On Tue, Jun 19, 2001 at 07:09:40PM +0200, Christine Kluka wrote: Now the error that I get is: xxx.cgi did not produce a valid header (name without value:got line variable $i is not imported at xxx.cgi line 65.) I need to declare the subroutine row in which the error is found to do a fetchrow later in the script, and I can't see an error in the subroutine itself. Help! You've got use strict, but you forgot to declare the variable $i: sub row { $r = shift(@_); @r = @_; $nfields = $r-nfields; for ($i=0; $i$nfields; $i++) { $fname = $r-fname($i); $r{$fname} = $r[$i]; } return %r; } Ronald
RE: DBI Connect Failure
-Original Message- From: Christine Kluka [mailto:[EMAIL PROTECTED]] Sent: Wednesday, June 20, 2001 8:25 PM To: Ronald J Kimball Cc: [EMAIL PROTECTED] Subject: Re: DBI Connect Failure Ronald, Thanks for your reply. I: - declared $i=0; -- it still fails to import That means this: for (my $i=0; $i$nfields; $i++) { ^^ that's declaring a variable and it is a requirement of the 'use strict' pragma. Neil I've tried various other things, like - declaring $i as STDIN, then chomping it -- same result - using code from http://www.perl.com/pub/1999/10/DBI.html#About_Relational_Datab ases_Gener for DBI-connect, but also using the code that I have -- got method not supported Ill keep trying. In the meantime, any ideas are appreciated, thanks! Christine Ronald J Kimball wrote: On Tue, Jun 19, 2001 at 07:09:40PM +0200, Christine Kluka wrote: Now the error that I get is: xxx.cgi did not produce a valid header (name without value:got line variable $i is not imported at xxx.cgi line 65.) I need to declare the subroutine row in which the error is found to do a fetchrow later in the script, and I can't see an error in the subroutine itself. Help! You've got use strict, but you forgot to declare the variable $i: sub row { $r = shift(@_); @r = @_; $nfields = $r-nfields; for ($i=0; $i$nfields; $i++) { $fname = $r-fname($i); $r{$fname} = $r[$i]; } return %r; } Ronald __ Please Note : Only the intended recipient is authorised to access or use this e-mail. If you are not the intended recipient, please delete this e-mail and notify the sender immediately. The contents of this e-mail are the writer's opinion and are not necessarily endorsed by the Gunz Companies unless expressly stated. We use virus scanning software but exclude all liability for viruses or similar in any attachment.
Re: DBI Connect Failure
Neil, Thanks, I added my to this variable and to the array and hash declarations in my row subroutine -- this eliminated the not imported errors. Now when I execute the script I am prompted for explicit package names for each instance of a scalar, array or hash. I believe that if I declare the fully qualified package name where the database handler is invoked, this should take care of the problem. I've tried several ways of doing this, but they all fail on syntax or for more serious reasons. Here's my latest attempt: #!/usr/local/bin/perl package PgSQL; use strict; use PgSQL::Cursor; use CGI qw(:standard); #General variables $packageName = PgSQL; $dbh = Defined in $packageName; print In $packageName, $PgSQL, $dbh\n; print In $packageName, $main::$PgSQL\n; my $dbh = db_connect(mydb) or die Error: $Postgres::error; Help! Thanks, Christine Neil Lunn wrote: -Original Message- From: Christine Kluka [mailto:[EMAIL PROTECTED]] Sent: Wednesday, June 20, 2001 8:25 PM To: Ronald J Kimball Cc: [EMAIL PROTECTED] Subject: Re: DBI Connect Failure Ronald, Thanks for your reply. I: - declared $i=0; -- it still fails to import That means this: for (my $i=0; $i$nfields; $i++) { ^^ that's declaring a variable and it is a requirement of the 'use strict' pragma. Neil I've tried various other things, like - declaring $i as STDIN, then chomping it -- same result - using code from http://www.perl.com/pub/1999/10/DBI.html#About_Relational_Datab ases_Gener for DBI-connect, but also using the code that I have -- got method not supported Ill keep trying. In the meantime, any ideas are appreciated, thanks! Christine Ronald J Kimball wrote: On Tue, Jun 19, 2001 at 07:09:40PM +0200, Christine Kluka wrote: Now the error that I get is: xxx.cgi did not produce a valid header (name without value:got line variable $i is not imported at xxx.cgi line 65.) I need to declare the subroutine row in which the error is found to do a fetchrow later in the script, and I can't see an error in the subroutine itself. Help! You've got use strict, but you forgot to declare the variable $i: sub row { $r = shift(@_); @r = @_; $nfields = $r-nfields; for ($i=0; $i$nfields; $i++) { $fname = $r-fname($i); $r{$fname} = $r[$i]; } return %r; } Ronald __ Please Note : Only the intended recipient is authorised to access or use this e-mail. If you are not the intended recipient, please delete this e-mail and notify the sender immediately. The contents of this e-mail are the writer's opinion and are not necessarily endorsed by the Gunz Companies unless expressly stated. We use virus scanning software but exclude all liability for viruses or similar in any attachment.
Re: DBI Connect Failure
On Wed, Jun 20, 2001 at 03:47:31PM +0200, Christine Kluka wrote: Neil, Thanks, I added my to this variable and to the array and hash declarations in my row subroutine -- this eliminated the not imported errors. Now when I execute the script I am prompted for explicit package names for each instance of a scalar, array or hash. I believe that if I declare the fully qualified package name where the database handler is invoked, this should take care of the problem. I've tried several ways of doing this, but they all fail on syntax or for more serious reasons. That's another error that means you haven't declared your variables. When you use strict 'vars', you have three options for each variable. Declare it with my: my $lexical_variable; $lexical_variable = 7; print $lexical_variable; Declare it with use vars: use vars qw/ $global_variable /; $global_variable = 7; print $global_variable; Specify the package name every time you use it: $main::global_variable = 7; print $main::global_variable; Most people prefer the first two options. Ronald
Re: DBI Connect Failure
I strongly prefer the first option. For programs that don't fit on one screen, using lexical (my) variables makes it much easier to keep one part of the program from interfering with the rest. I have occasionally used global variables, but only for very specific data sharing between modules. -- Mac :}) ** I normally forward private database questions to the DBI mail lists. ** Give a hobbit a fish and he'll eat fish for a day. Give a hobbit a ring and he'll eat fish for an age. - Original Message - From: Ronald J Kimball [EMAIL PROTECTED] To: Christine Kluka [EMAIL PROTECTED] Cc: Neil Lunn [EMAIL PROTECTED]; [EMAIL PROTECTED] Sent: Wednesday, June 20, 2001 06:55 Subject: Re: DBI Connect Failure On Wed, Jun 20, 2001 at 03:47:31PM +0200, Christine Kluka wrote: Neil, Thanks, I added my to this variable and to the array and hash declarations in my row subroutine -- this eliminated the not imported errors. Now when I execute the script I am prompted for explicit package names for each instance of a scalar, array or hash. I believe that if I declare the fully qualified package name where the database handler is invoked, this should take care of the problem. I've tried several ways of doing this, but they all fail on syntax or for more serious reasons. That's another error that means you haven't declared your variables. When you use strict 'vars', you have three options for each variable. Declare it with my: my $lexical_variable; $lexical_variable = 7; print $lexical_variable; Declare it with use vars: use vars qw/ $global_variable /; $global_variable = 7; print $global_variable; Specify the package name every time you use it: $main::global_variable = 7; print $main::global_variable; Most people prefer the first two options.
Re: DBI Connect Failure
On Tue, Jun 19, 2001 at 07:09:40PM +0200, Christine Kluka wrote: Now the error that I get is: xxx.cgi did not produce a valid header (name without value:got line variable $i is not imported at xxx.cgi line 65.) I need to declare the subroutine row in which the error is found to do a fetchrow later in the script, and I can't see an error in the subroutine itself. Help! You've got use strict, but you forgot to declare the variable $i: sub row { $r = shift(@_); @r = @_; $nfields = $r-nfields; for ($i=0; $i$nfields; $i++) { $fname = $r-fname($i); $r{$fname} = $r[$i]; } return %r; } Ronald