Connecting Tech Pros Worldwide Forums | Help | Site Map

MySQL data access

Newbie
 
Join Date: Apr 2007
Location: singapore
Posts: 8
#1: Apr 19 '07
hi,

can u please explain how to retrieve two colums of data from two different mysql table using perl with example.


thank u

savanm's Avatar
Member
 
Join Date: Oct 2006
Location: chennai
Posts: 86
#2: Apr 23 '07

re: MySQL data access


hi,

Expand|Select|Wrap|Line Numbers
  1. use DBI;
  2.  
  3. my $dbh = DBI->connect("DBI:mysql:database=perldbi;host=localhost","root","");
  4.  
  5. my $userid;
  6. my $sth = $dbh->prepare('select usrid from foo1');
  7. $sth->execute() or die $dbh->errstr;
  8. $sth->bind_columns(\$userid);
  9. while ($sth->fetch) {
  10.     print "\t$userid\n";
  11. }
  12. $sth->finish();
  13.  
  14. my $name;
  15. my $sth1=$dbh->prepare('select name from test');
  16. $sth1->execute() or die $dbh->errstr;
  17. $sth1->bind_columns(\$name);
  18. while ($sth1->fetch) {
  19.     print "\t$name\n";
  20. }
  21. $sth1->finish();
  22.  
  23. $dbh->disconnect();
  24.  
Hi here two tables foo and test from a single database perldbi,

And we retrieve userid from foo and name from test, i think this is ur need
Reply