unblessed reference... 
Author Message
 unblessed reference...

Hi all,

I am getting this error:

Cant call method "prepare" on unblessed refenece at common.lib line nnn,
etc...

The sub in common.lib

sub get_data{


  print "sql=$sql db=$Db <br>\n";
  my $sth = $Db->prepare($sql)
  || print "<br><br><font color=red>"
           ."Could not prepare sql statement with"
           ." <br>$SPACER Sql=$sql"
           ." <br>$SPACER caused err: $DBI::errstr </font>";
  my $rc = $sth->execute()
  || print "<br><br><font color=red>"
           ."Could not execute sql statement with"
           ." <br>$SPACER Sql=$sql"
           ." <br>$SPACER caused err: $DBI::errstr </font><br>";

  return ($sth->fetchall_arrayref());

Quote:
} #end get_data

The call:

$str = 'select col1 from tab1';

$all_data = &get_data($str, $db_conn);

Any help would be greately appreciated

--
Gabriel Bolano
(510) 936-3559



Sat, 15 May 2004 01:50:03 GMT  
 unblessed reference...
On Mon, 26 Nov 2001 16:50:03 -0800, gabriel bolano said:

Quote:
>Hi all,

>I am getting this error:

>Cant call method "prepare" on unblessed refenece at common.lib line nnn,
>etc...

Looks like you are trying to call a method on an object (which in
Perl is just a reference that has been bless()ed into a class), but
are calling it on an ordinary reference instead.

Quote:
>sub get_data{


>  ...
>  my $sth = $Db->prepare($sql)

I assume that you expect $Db to contain a database handle object
from the DBI class. The error message above is teling you that it
doesn't.

Quote:
>  ...
>} #end get_data

>The call:

>$str = 'select col1 from tab1';
>$all_data = &get_data($str, $db_conn);

So where does $db_conn come from? I am assuming you did something
like:

        use DBI;
        my $db_conn = DBI->connect(
                $dsn, $user, $pass,
                {RaiseError => 1}
        ) or die "Can't connect: $DBI::errstr";

Did you test for success? No-one can really help you without seeing
that part of your code.

Cheers,
Damian



Just another Perl Hacker,### http://home.pacific.net.au/~djames.hub



Sat, 15 May 2004 02:53:55 GMT  
 unblessed reference...


Quote:
> I am getting this error:

> Cant call method "prepare" on unblessed refenece at common.lib line nnn,
> etc...
> sub get_data{

>   my $sth = $Db->prepare($sql)

$Db is not what you think it is.  check your arguments to
this function to make sure you have an instance in $Db.

--

CGI Meta FAQ - http://www.perl.org/CGI_MetaFAQ.html
Troubleshooting CGI scripts - http://www.perl.org/troubleshooting_CGI.html



Sat, 15 May 2004 05:50:36 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. recursive SELECT on table - unblessed reference

2. Unblessed reference.

3. unblessed reference

4. Unblessed reference error when using DBI::DBD

5. Unblessed reference

6. screen and unblessed reference

7. Error involves unreferenced scalar, unblessed reference. Please help, testcase provided.

8. Error involves unreferenced scalar, unblessed reference. Please help, testcase provided.

9. Can't call method "isaCGI" on unblessed reference at (eval 11) line 1.

10. Error involves unreferenced scalar, unblessed reference. Please help, testcase provided.

11. RPC::XML::Client - method is_fault called on unblessed ref

12. Problem with method - unblessed

 

 
Powered by phpBB® Forum Software