Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

DBD::mysql barfs

by scottstef (Curate)
on May 21, 2001 at 01:30 UTC ( #81869=perlquestion: print w/ replies, xml ) Need Help??
scottstef has asked for the wisdom of the Perl Monks concerning the following question:

I had some problems installing DBD::mysql, however it stated it installed clean. I am using the code from the tutorial stephen wrote on mysql located here. However when I run this code:

#!/usr/bin/perl -w use strict; use DBI; my $dbh = DBI->connect('DBI:mysql:quotes', 'scott', 'some_password') or die "dumbass it didn't work: '$DBI::errstr'; stopped"; my $sth = $dbh->prepare(<<END_SQL) or die "Couldn't prepare statement: + $DBI:errstr; stopped"; SELECT count, phrase, author, submitted_by FROM qod WHERE coun +t = `1` END_SQL #This is Line 10 $sth->execute() or die "Couldn't make query: '$DBI:errstr'; stopped"; + while ( my ($count, $phrase, $author, $submitted_by) = $sth->fetch_arr +ay()) { print "Field1: $count\n Field2: $phrase\n Field3: $aut +hor\n Field4: $submitted_ by\n\n"; } $dbh->disconnect();

I get this error
Global symbol "$DBI" requires explicit package name at ./dbitest.pl line 10.
Global symbol "$DBI" requires explicit package name at ./dbitest.pl line 12.
Execution of ./dbitest.pl aborted due to compilation errors.

If I comment out use strict <nbsp&><nbsp&><nbsp&>I get a different goofy error:

/usr/libexec/ld.so: Undefined symbol "_mysql_init" called from perl:/usr/local/libdata/perl5/site_perl/i386-openbsd/auto/DBD/mysql/mysql.so at 0x401bc284

What am i doing wrong or do I need to reinstall the module?

Comment on DBD::mysql barfs
Download Code
Re: DBD::mysql barfs
by Caillte (Friar) on May 21, 2001 at 02:32 UTC

    If your code is exactly as yo uentered here then you made one little mistake. Your error revolves around the fragment of code "$DBI:errstr". Now perl interprets this as (Contents of the variable $DBI)(the string ':errstr'). What I think you want is $DBI::errstr (note the second colon). This corresponds to tthe contents of the variable $errstr in the package DBI.

    $japh->{'Caillte'} = $me;

Re: DBD::mysql barfs
by olly (Scribe) on May 21, 2001 at 03:09 UTC
    I am not shure if the missing : is the problem because I get a syntax error when I leave it out. Here is the mysql code that does the job for me
    $dsn = "DBI:$db_driver:database=$db_database;host=$db_hostname;port=$d +b_port"; $dbh = DBI->connect($dsn, $db_user, $db_password) || die "cannot conne +ct: " . $DBI::errstr; $sth = $dbh->prepare(qq` insert into solid_gear (product_name, product_publisher, product_price, product_url, product_ +picture_name, url1, url2, url3, url4, name1, name2, name3, name4, pro +duct_review, date, author_id) values ('$product_name','$product_publisher','$product_price','$product_url', +'$product_picture_name','$url1','$url2','$url3','$url4','$name1','$na +me2','$name3','$name4','$product_review','$date','$author_id') `) || die "Cannot prepare: " . $dbh->errstr(); $sth->execute() || die "Cannot execute: " . $sth->errstr(); $sth->finish(); $dbh->disconnect;
    I hope this is any help (just a quick cut and paste)

    Imagination is more important then knowledge -Einstein-

Re: DBD::mysql barfs
by Caillte (Friar) on May 21, 2001 at 04:44 UTC

    I tested this on my machine and changing $DBI:errstr to $DBI::errstr removed all the errors (apart from the one createdby you putting a comment after the END_SQL block ;)

    $DBI::errstr anmd $dbh->errstr are essentially the same variable, called in different contexts. Calling $DBI::errstr is making a non-object oriented call to the variable in the package DBI. $dbh->errstr calls the same variable (usually) via the object $dbh. For an explanation of the (usually) part I suggest you look at object oriented tutorials available on this site as a full explanation is beyond the scope of this reply (re: it is past midnight and I have to get up in 6 hours ;))

    Suffice to say that, in most cases, replacing one by another will usually work

    scottstef, you say that you still have the same problem after updating the code the way I suggested. This is surprising as I managed to get your code working fine and, apart from your colon error your code appears to work pretty well. Perhaps if you were to place your current code on this node, along with the errors you are getting, one of us could take a look and make some suggestions.

    $japh->{'Caillte'} = $me;

Re: DBD::mysql barfs
by andye (Curate) on May 21, 2001 at 17:27 UTC
    SELECT count, phrase, author, submitted_by FROM qod WHERE count = `1` Are those backticks around the number one, rather than single quotes?

    andy.

Re: DBD::mysql barfs
by scottstef (Curate) on May 21, 2001 at 17:55 UTC
    Thanks all who have posted suggestions, I have tried these and it still barfs. (With the same error) I think the problem has to do with the dbd module, I think I will try to reinstall it.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://81869]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (5)
As of 2014-07-10 07:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (202 votes), past polls