The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

cPAddon Script DBI problem

Discussion in 'General Discussion' started by mrtwister76, Dec 27, 2008.

  1. mrtwister76

    mrtwister76 Registered

    Joined:
    Oct 20, 2008
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    1
    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
     
  2. cPDan

    cPDan cPanel Staff
    Staff Member

    Joined:
    Mar 9, 2004
    Messages:
    711
    Likes Received:
    4
    Trophy Points:
    18
    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!
     
  3. sdstein7

    sdstein7 Registered

    Joined:
    Jul 2, 2009
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    1
    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::DBI 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.
     
  4. cPDan

    cPDan cPanel Staff
    Staff Member

    Joined:
    Mar 9, 2004
    Messages:
    711
    Likes Received:
    4
    Trophy Points:
    18
    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?)
     
  5. sdstein7

    sdstein7 Registered

    Joined:
    Jul 2, 2009
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    1
    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
     
  6. cPDan

    cPDan cPanel Staff
    Staff Member

    Joined:
    Mar 9, 2004
    Messages:
    711
    Likes Received:
    4
    Trophy Points:
    18
    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.
     
  7. sdstein7

    sdstein7 Registered

    Joined:
    Jul 2, 2009
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    1
    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
     
Loading...

Share This Page