Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic MYSQL with Perl? (Read 2173 times)
Ty
Junior Member
**
Offline


I love YaBB 1 Gold!

Posts: 63
Joined: Aug 25th, 2001
MYSQL with Perl?
Apr 11th, 2002 at 2:49am
Print Post  
LOL ok guys I blew a total brain fart... but I could have sworn I read somewhere that you can now access Mysql from perl..... if so would anyone happen to know how to do so.

*Reason: is that I was ripping news from a .txt file generated by a php news script I made.  Later I decided to convert the db to MySql because of it's speed and ease of show dynamic results.

*Problem: don't have a clue how to extract MySql varables in Perl

*Solutions: figure out problem to above....... or have to write an additional function for PHP news script in order to blast the headlines to both MySql and a .txt file.

Any help would be great Grin  Thanks.... Ty


P.S.  If you guys are into PHP scripts I will be starting up an archive soon of the most usfull ones I have come accross..... if you are interested just head on over to http://www.b2spec.cjb.net/
  
Back to top
WWW  
IP Logged
 
Dave Baughman
God Member
*****
Offline


I want my MTV

Posts: 2039
Location: Murfreesboro
Joined: May 18th, 2001
Gender: Male
Re: MYSQL with Perl?
Reply #1 - Apr 11th, 2002 at 4:08am
Print Post  
You're right, you can access MySQL (and tons of other DB's) using Perl, all through the wonder of the DBI module. Here's the only code example I have on hand (haven't needed to use it in many of my scripts):

Code
Select All
# activate module
use DBI();

# connect
my $dbh = DBI->connect("DBI:mysql:database=dbName;host=localhost", "username",
"password") || die "Can't connect: $DBI::errstr";


# execute query
my $sth = $dbh->prepare("SELECT lhpmtext, nlpmtext, bannertext, website FROM clientdata WHERE clientID='$php{clientID}'");
$pm_text = $sth->execute();

while(my $ref = $sth->fetchrow_hashref())
	  {
	 $my_lh = "$ref->{'lhpmtext'}";
	 $my_nl = "$ref->{'nlpmtext'}";
	 $my_ib = "$ref->{'bannertext'}";
	 $website = "$ref->{'website'}";
	  }

# clean up
$sth->finish();
$dbh->disconnect();
 



The $php{} hash is from a little earlier in the script. I took a php sessionID and brought it into my perl script, then took it apart and got the info I needed from it. Kinda neat, and saved me from needing more cookies for the Perl part of the script.

And here's my favorite little DBI tutorial:
http://www.devshed.com/Server_Side/Perl/Carping/page1.html

Good luck!

- Dave
« Last Edit: May 8th, 2012 at 4:14pm by Dave Baughman »  

I'm not sure if it's ignorance or apathy, but I don't know and I don't care.
Back to top
WWW  
IP Logged
 
Jedi
Full Member
***
Offline



Posts: 104
Location: Sarasota
Joined: Mar 28th, 2002
Gender: Male
Re: MYSQL with Perl?
Reply #2 - Apr 14th, 2002 at 4:05pm
Print Post  
Wow, that's so much longer and more complicated than the PHP integration with mySQL. Sad really Tongue Wink
  
Back to top
 
IP Logged
 
Dave Baughman
God Member
*****
Offline


I want my MTV

Posts: 2039
Location: Murfreesboro
Joined: May 18th, 2001
Gender: Male
Re: MYSQL with Perl?
Reply #3 - Apr 14th, 2002 at 5:11pm
Print Post  
Well, maybe sad that it's longer, but much more flexible. You can connect to almost any database with the same program with DBI. With php, you usually have to go through and find every mysql_ statement and change it to what the new database type is. Easier, but much less scalable and robust. Wink
  

I'm not sure if it's ignorance or apathy, but I don't know and I don't care.
Back to top
WWW  
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint