MySQL data access

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vignesh1985
    New Member
    • Apr 2007
    • 11

    MySQL data access

    hi,

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


    thank u
  • savanm
    New Member
    • Oct 2006
    • 85

    #2
    hi,

    Code:
    use DBI;
    
    my $dbh = DBI->connect("DBI:mysql:database=perldbi;host=localhost","root","");
    
    my $userid;
    my $sth = $dbh->prepare('select usrid from foo1');
    $sth->execute() or die $dbh->errstr;
    $sth->bind_columns(\$userid);
    while ($sth->fetch) {
    	print "\t$userid\n";
    }
    $sth->finish();
    
    my $name;
    my $sth1=$dbh->prepare('select name from test');
    $sth1->execute() or die $dbh->errstr;
    $sth1->bind_columns(\$name);
    while ($sth1->fetch) {
    	print "\t$name\n";
    }
    $sth1->finish();
    
    $dbh->disconnect();
    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
    Last edited by miller; Apr 23 '07, 11:58 PM. Reason: Code Tag and ReFormatting

    Comment

    Working...