#1 (permalink)  
Old 12-27-2008, 01:58 PM
Registered User
 
Join Date: Oct 2008
Posts: 1
mrtwister76 is on a distinguished road
cPAddon Script DBI problem

Hi All,

I'm trying to write my first cPAddon install script.
I need to use the DBI perl module in order to setup some details in the database after the installation.

If I SSH to the server as root, I can run perl scripts using the DBI module without problem, however, whist attempting to use DBI via cPanels 'Site Software' I get the following error:

Code:
Can't locate object method "connect" via package "DBI" (perhaps you forgot to load "DBI"?)
Anybody know how to load the DBI module when writing install scripts?
I'm using the following:

Code:
use DBI;
and in order to attempt to get the DBI module on the path:

Code:
BEGIN { unshift @INC, qw(/usr/lib/perl5/5.8.8/x86_64-linux/ 
/usr/lib/perl5/site_perl/5.8.8/x86_64-linux/Bundle/ 
/usr/lib/perl5/site_perl/5.8.8/x86_64-linux/Bundle/DBD 
/usr/lib/perl5/site_perl/5.8.8/x86_64-linux/auto/DBD/mysql); }
If I don't specify the above paths, perl uses these paths:

Code:
/usr/local/cpanel 
/usr/local/cpanel/cpaddons 
/usr/local/cpanel 
/usr/local/cpanel/perl 
/usr/local/cpanel/Cpanel/CPAN/overload/__Digest /usr/local/cpanel/build-tools/stubs 
/usr/lib/perl5/5.6.2/x86_64-linux 
/usr/lib/perl5/5.6.2 
/usr/lib/perl5/site_perl/5.6.2/x86_64-linux 
/usr/lib/perl5/site_perl/5.6.2 
/usr/lib/perl5/site_perl
For some reason, it's using the 5.6.2 path instead of the 5.8.8.

My script is located in /usr/local/cpanel/cpaddons/cPanel/Ecommerce

Any help appreciated ( this is driving me mad ).

Thanks,
Mark
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 12-30-2008, 10:18 PM
cPanel Staff
 
Join Date: Mar 2004
Posts: 645
cpdan is on a distinguished road
Hello,

'use DBI;' is indeed how to load to load a perl module.

The "weird" INC paths are due to the way cPanel is compiled.

Adding paths to @INC might allow a module to be included *BUT*:
- the perl version is likely to be different on different server or change (IE the paths would be wrong most of the time)
- if there is any linking/XS involved (DBI and driver's) there could be issues also (perl binary vs. cpanel binary)

If you can outline what you are needing DBI for I will be able to recommend a solution, thanks!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 07-02-2009, 12:22 PM
Registered User
 
Join Date: Jul 2009
Posts: 3
sdstein7 is on a distinguished road
Any solution to DBI connect problem?

I am also getting the message
"Can't locate object method connect via package DBI at ..."

My OS is Red Hat Linux 5.3 and the context is installation of Koha library software. I get the same error in two different places: trying to connect to Koha and trying to run zebraqueue_daemon.pl.

I am certain that DBI is installed, and both DBI directory and DBI.pm are in my @INC path, and that the perl code includes the statement 'use DBI'.
(I did have to do a 'force install' on Bundle:BI from cpan.)

I have written a very simple script with a dbi->connect command and get the same error.

If anybody could post a solution for this, I would be most appreciative.

Sanford Stein
CyberTools Inc.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 07-02-2009, 12:48 PM
cPanel Staff
 
Join Date: Mar 2004
Posts: 645
cpdan is on a distinguished road
Quote:
Originally Posted by sdstein7 View Post
I am also getting the message
"Can't locate object method connect via package DBI at ..."
...
If anybody could post a solution for this, I would be most appreciative..
See my last post for technical details but essentially to recommend a solution we need to know what you are trying to do with the database handle. (i.e. why is the handle necessary, what is it for?)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 07-02-2009, 02:30 PM
Registered User
 
Join Date: Jul 2009
Posts: 3
sdstein7 is on a distinguished road
Response to cpdan

cpdan,

The offending line of code is:

my $dbh= DBI->connect("DBI:$db_driver:dbname=$db_name;host=$db_ host;port=$db_port",
$db_user, $db_passwd) or die $DBI::errstr;

$db_driver is 'mysql', $db_name is 'koha', $db_host is 'localhost',
$db_port is 8080

So basically we are trying to connect to a mysql database. I can connect using mysql so I am certain the the parameters are correct. I did not write this code--it is part of the koha distribution.

I hope this answers your question.

Your comment in your last post about Perl versions may be on target. I have noted that the Red Hat distribution of Perl is 5.8.8 and the CPAN stuff that gets installed goes into directories labeled 5.8.9. But all the DBI stuff is in 5.8.9 directories, which are the ones included in the @INC path:

perl -e "print join(\"\n\", @INC);"
/usr/share/koha/lib
/usr/local/lib/perl5/5.8.9/i686-linux
/usr/local/lib/perl5/5.8.9
/usr/local/lib/perl5/site_perl/5.8.9/i686-linux
/usr/local/lib/perl5/site_perl/5.8.9

Thanks for any help you can provide.

Sanford Stein
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 07-02-2009, 02:52 PM
cPanel Staff
 
Join Date: Mar 2004
Posts: 645
cpdan is on a distinguished road
Quote:
Originally Posted by sdstein7 View Post
So basically we are trying to connect to a mysql database
Thanks, I do understand that, the point is though that there should be no need to connect to the database as it's all handled for you. So the question isn't "how" but *why* do you need to connect to the data base? What are you wanting to accomplish with $dbh?

It appears you are wanting to connect to a global data base (i.e not the one associated with the install) to, perhaps, register an installation in some manner?

If so your best bet is to have an external script do it:

system("/usr/bin/my_register_install_with_koho_db", @args);

That will work around any compilation issues and also potential more-than-one-db-connection issues.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 07-02-2009, 03:35 PM
Registered User
 
Join Date: Jul 2009
Posts: 3
sdstein7 is on a distinguished road
cpdan,

My assignment here is to do an install of Koha, a freeware library management system, for evaluation purposes. Koha is written in Perl and uses the mysql database, Apache, and zebra, a Z39.50 based retrieval product (also freeware).

Users would connect to the database from their Web browsers, by entering the address http://ourserver/phpmyadmin, which I presume connects to a certain port, Here Koha and zebra work together to give the user a connection to the mysql database. $dbh is the handle by which mysql and Koha communicate --I confess to not knowing the details, this is all "under the hood". But it is at this point -- attempting to connect using a browser -- that the error occurs. (It also occurs attempting to queue zebra.)

If I wrote an external script, it would be a challenge for me to know exactly where this piece would fit in the existing design of the product, which is not really documented.

Are you saying that there is not a way to make this work otherwise?
That is, there is no way that DBI->connect can be located via some different way of installing CPAN modules or some different path settings?

Thanks,
SS
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Tags
cpaddon , dbi , install script

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 06:51 PM.


Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
© cPanel Inc