CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: DBI:
Getting data from a table, problem is probably stupidity(Yes it was, fixed now)

 



Scuzzball
New User

Jan 12, 2012, 7:02 AM

Post #1 of 5 (17327 views)
Getting data from a table, problem is probably stupidity(Yes it was, fixed now) Can't Post

I'm trying to get info out of a database. The testing table I have has one data entry, URL, and I cannot get it out in perl.

This is the code: http://pastebin.com/7gaYceAY
This is where you can view the output: http://uf.serveftp.com/cgi-bin/display.cgi

I'm using \n instead of <br /> right now as I've been running it like a perl script so I can get more error messages.

But what I need to know is how I'm supposed to get the data out of the table after I execute the SQL query. I've just been copying things off different tutorials and modifying the variable names so they work, but none have worked.

Thank you for any help.


(This post was edited by Scuzzball on Jan 12, 2012, 7:52 AM)


FishMonger
Veteran / Moderator

Jan 12, 2012, 7:22 AM

Post #2 of 5 (17320 views)
Re: [Scuzzball] Getting data from a table, problem is probably stupidity [In reply to] Can't Post

http://perl-begin.org/tutorials/perl-for-newbies/


Scuzzball
New User

Jan 12, 2012, 7:33 AM

Post #3 of 5 (17318 views)
Re: [FishMonger] Getting data from a table, problem is probably stupidity [In reply to] Can't Post

But that has nothing do do with the DBI module, and everything else works, I just need help on the syntax of the one command where I get the data to an array.


FishMonger
Veteran / Moderator

Jan 12, 2012, 7:48 AM

Post #4 of 5 (17316 views)
Re: [Scuzzball] Getting data from a table, problem is probably stupidity [In reply to] Can't Post

I posted that link because based on your post, it appears that you're not understanding some of the basics of Perl programming.

For the sql issue, fetchrow_array() is a statement handle method, not a database handle method.

change:

Code
while (@row = $dbh->fetchrow_array()) {

to:

Code
while ( my @row = $query->fetchrow_array ) {



Scuzzball
New User

Jan 12, 2012, 7:51 AM

Post #5 of 5 (17314 views)
Re: [FishMonger] Getting data from a table, problem is probably stupidity [In reply to] Can't Post

Okay, thank you very much. I had wondered why I used the database handle instead of the query, but the two tutorials I had looked at used the database handle.

And yeah, I've learned perl by looking at the code my friend wrote, and getting him to explain it to me and then working off tutorials and assuming things from other languages. It worked till databases, where I was just copying tutorials.

Thanks again.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives