Click to See Complete Forum and Search --> : connecting Perl w/ MySQL?!


[k]
09-29-2000, 10:50 AM
Okay... I'm really new at this and here's what I want to know:

I've got a website and I want to use a perl script to go look for data in a database (DUH! http://www.linuxnewbie.org/ubb/rolleyes.gif ). Let's say I'm putting the data in MySQL format, how do I make the connection? I mean I have to put my database on the server right? 'Cause right now it's sitting on my box at home!

So I just want to look for the data I need and plaster it on the site.

What do I do! http://www.linuxnewbie.org/ubb/confused.gif

------------------
[k]

"This neverworld which you desire is only in your mind."
- Dream Theater

[This message has been edited by [k] (edited 29 September 2000).]

TheLinuxDuck
09-29-2000, 10:54 AM
http://www.linuxnewbie.org/ubb/smile.gif There's a fellow here that goes by mangeli that has been working on something quite the like with your interest. I would suggest scanning this forum for recent (last few days) posts from him, and read through them.. in fact, I believe he has his perl source listed somewhere.



------------------
TheLinuxDuck
Wait... that's a penguin?!?!?
:wq

takshaka
09-29-2000, 03:12 PM
You'll want to install the DBI (http://search.cpan.org/search?dist=DBI) and DBD::mysql (http://search.cpan.org/search?dist=DBD-mysql) modules from CPAN (http://www.cpan.org/).

klamath
09-29-2000, 04:18 PM
I mean I have to put my database on the server right

All decent database engines can be configured to accept connections over TCP/IP.

------------------
- Klamath
Get my GnuPG Key Here (http://klamath.dyndns.org/mykey.asc)

jemfinch
09-29-2000, 04:27 PM
use CGI;

my $dbd = 'mysql';
my $server = 'databaseserver.domain.tld';
my $database = 'web_database';
my $dbh = DBI->connect("DBI:$dbd:$database:$server", 'user', 'password');
# Now we're connected.

my $sth = $dbh->prepare("insert into table (column1, column2) values (?, ?)");
$sth->execute('foo', 'bar');

$sth = $dbh->prepare("select * from table where column1=?");
$sth->execute('foo');

while($_ = $sth->fetchrow()) {
print "$_\n";
} # Note that you can also put each individual column into an array, if you're selecting more than one column.


Jeremy

martinnitram
09-05-2001, 09:48 PM
A quite good reference for MYSQL DBI/DBD:
http://www.savebaseball.com/mysql/DBD_3.21.X.php3

Hope this helpful.

jemfinch
09-05-2001, 11:49 PM
Of course, this thread was almost a year old...

Jeremy